Saturday, 30 May 2015

How to print a URL in PDF from SQR

An ITToolbox post led me to explore this topic. More importantly I had an eureka moment long time ago when I had accidentally came across a hyperlink in a PDF generated from a SQR program but had a malformed URL. At the time, I didn't bother to find out why it was malformed nor fix it. I have done so now and you will see how you can have an clickable URL in the PDF generated from a SQR that the user(s) can click and navigate to directly.

The key to making the PDF understand the hyperlink lies in the text "Website:" that you will have to add before the URL. That alone does not help you to generate a URL that you can click from PDF. You have to have 2 more print statements to print a blank after the URL and another print statement (yes you have to print something) after the URL for it to be recognized as a URL.

Here is the SQR code that I used for testing this out -
1:  #define widthofpage 126  
2:  #define widthofpage2 127  
3:    
4:    
5:  #define debugY  
6:    
7:    
8:  begin-setup  
9:   page-size 75 130  
10:    
11:    declare printer  
12:     type     = HPLASERJET  
13:     orientation  = portrait  
14:     top-margin  = 0.30  
15:     left-margin  = 0.1  
16:     font     = 5  
17:     point-size  = 7  
18:     line-size   = 11  
19:  end-setup  
20:    
21:  begin-report  
22:    
23:   do Init-Report  
24:  end-Report  
25:    
26:  !***********************************************************************  
27:  ! Procedure: Init-Report                       *  
28:  !       The main driving procedure                *  
29:  !***********************************************************************  
30:  begin-Procedure Init-Report  
31:    
32:    
33:   do Process-Main  
34:    
35:  end-procedure  
36:    
37:  !***********************************************************************  
38:  ! Procedure: Process-Main                       *  
39:  !      Control the process either by choosing paygroup or by   *  
40:  !      Employee ID's entered on the run control panel      *  
41:  !***********************************************************************  
42:  begin-procedure Process-Main  
43:    
44:     !Do Print-Paygroup-Select  
45:     do print-hyperlink  
46:    
47:  end-procedure  
48:    
49:  begin-procedure print-hyperlink  
50:   graphic () font 9 6       
51:   print 'Website:http://www.google.com' (3,30)  
52:   print ' ' ()   
53:   graphic () font 12 8  
54:   Print 'How to print a URL in PDF from SQR ' (-2,0) center  
55:    
56:  end-procedure  

The end result is that you can now see the URL with the hand icon (not captured in the screenshot but you can see the tooltip text as a result of the URL being recognized)



Clicking the link will prompt this security message from Adobe acrobat software. Click on "Allow" -

And voila, a new browser window opens the website link from the PDF document generated by the SQR.

The obvious drawback are that you cannot avoid the "Website:" text being printed in the PDF and you cannot have a shortcut text for the URL like you can have in the HTML anchor tag. So hopefully this will help you get the workaround you need while having to print a link in the PDF generated by SQR. Post a comment below if you have questions or have found a better way to achieve the same.

No comments:

Post a Comment