Expand my Community achievements bar.

Links Within PDF

Avatar

Former Community Member
I need a way to add links within a PDF.



This would react similar to Adobe Acrobat's settings, but I need a solution using LiveCycle Designer (7.0).



Any help would be greatly appreciated.
100 Replies

Avatar

Former Community Member
Well here is what I came up with and I don't know if it is the best way or not but here it is. Maybe someone else has a better way.



I took a form with 3 pages and added a static text field on the first and entered in a few paragraphs of text. Then I drew a button field on top of one of the words in the static text field. I set the appearance to custom and set the border and fill colors to none. I deleted the caption so now the button has no appearance. With the button selected I entered the following JavaScript code in the click event for the button.



xfa.host.currentPage = 2; //go to the 3rd page in the file.



I tested it out in Preview and when I clicked on the word I was taken to page 3 of the file.



What do you think?

Avatar

Former Community Member
This works for a single PDF (thanks much!!)



We stitch xdp's together (creating one PDF) and I need a way to code the link specifically for a particular page on a particular form.



We do name each and every page (on each and every form) uniquely so it would mean anything to our graphic designers - I just need some help on coding the specifics.



For example: Form 1234 includes P1_1234, P2_1234

Form 567 includes P1_567, P2_567, P3_567 (and a blank page)



The other catch is that the forms stitch together based on responses. So the 'packet' created may not be the same for every user.

Avatar

Former Community Member
Exactly what are you trying to get these "links" to jump to? Could you give me a concrete example of what one of these would do in a theoritical form so that I could understand better?



Warning: Accomplishing this may be very difficult/impossible considering your doing XDP packet stitching. But I'll try to come up with an idea.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
These links would jump to a page within a 'stitched' together pdf.



We design the forms in Designer and save as xdp's. The user can then user an interface to find all the forms they need - and the FormServer 'stitches' these xdp's together to make one single pdf packet This packet could potentially be unique everytime the user stitched xdp's together.



So, I cannot have the code simply count pages. I need the link to reference a specific 'target', 'flag', location to each form.



For example: After the user answers the questions, the new pdf packet gives a synopsis of their answers, a unique table of contents (based form their answers) and then the forms.

This TOC would contain links, so that the user can click on the form name listed and be brought to the beginning of that page in the packet.



Does this help clarify?

Avatar

Former Community Member
Hi,



I just recently completed writing a Java XDP stitching/parsing for a prominent Insurance Company, so I feel somewhat qualified to comment on this topic. What you would need to do is either:



A) Build the XDP for the TOC page with links as you stitch in each XDP child document to the parent document (most efficient) using Java code

- or -

B) Build the entire XDP package, then parse the whole XDP XML document tree to update the TOC page's link targets based on the child XDP documents that were stitched in (least efficient)

- then -

C) Render the XDP package as a PDF with Form Server



However, keep in mind that if 1 or more XDPs are using dynamic data flows, you'll never know exactly how many pages, so therefore you'll never be able to to update link targets server-side. In that case, I would investigate using clientside Javascript to update TOC link targets (if even that is possible, dunno).



Just my 2c,



Bryan Feagin

Avatar

Former Community Member
Hi John,



Another way to do this would be to use the



xfa.host.setFocus("
object_name")


method and some regular button objects.



The key here is that buttons can receive focus and setting focus to an object on a form will cause Acrobat to scroll to that object.



While I don't know the intricacies of how you stitch the forms together into the package, if you used a regular button object for the title of each form within the package (remember you can use the Appearance property on the Object palette's Field tab along with the Border palette to modify the appearance of the button to make it look like a title) and then generated a series of buttons in the TOC with each button containing a single line of script in its Click event which sets focus to the "title" button pertaining to a particular form within the package, you could effectively simulate a TOC with links to the various forms. Then, you could also use the same script on the form "title" buttons to bring the user back to the TOC if you made the TOC title a button.



The other thing is that this solution would work even if the content of a page overflows onto a new page since the new page is simply a new instance of the original page and your SOM expressions in the xfa.host.setFocus calls wouldn't be affected.



Since this is a little complicated to explain, I've attached a sample PDF which demonstrates what I'm talking about (note that the content of Page 1 overflows onto a new page yet the "links" still work).



Let me know if you have any questions.



Stefan

Adobe Systems

Avatar

Former Community Member
I also need to add links to a PDF. However, I have created a custom button field as a "click here" box that I want to either open a PDF or go to a specific page on our intranet. Can anyone help with the scripting?



Thanks!



Melanie

Avatar

Former Community Member
It sounds like you want to be able to open an existing document in Acrobat under certain circumstances and browse to a URL in the system's default browser under other circumstances.



You can do both using some methods on the Acrobat
app object which is available to you in your XFA scripts via the
app keyword:



app.openDoc(path); // open the specified PDF in Acrobat

app.launchURL(URL[, newWindow]); // launch the specified URL in the system's default browser


The
newWindow parameter of app.launchURL is optional: Set it to false to launch the URL in the current browser window (default); set it to true to launch the URL in a new browser window.



Note that executing app.launchURL from Acrobat will open the URL in the system's default browser and executing app.openDoc in a browser will cause a security violation.



I've attached a sample form which demonstrates how to use these methods.



Stefan

Adobe Systems

Avatar

Former Community Member
Stefan --



Is there some way to do this without the user having to put in the link? I want it to be automatic when they click on the button.



Thanks for your quick reply.



Melanie

Avatar

Former Community Member
How you pass the path to the file or the URL to the web page to the app.openDoc and app.launchURL methods, respectively, is specific to your requirements.



If you know ahead of time what the file name or URL is, then just use the methods like this:



app.openDoc("MyPDF.pdf");

app.launchURL("http://www.adobe.com");


The path/URL could even come from data that's merged into your form via an XML data file or a connection to a database or web service. It's entirely up to you!



Stefan

Adobe Systems

Avatar

Former Community Member
Stefan,



I guess this would work if in my XFA script I had the keyword APP. It is not in the listing. I have the following as the first link:



----- form1.AccessRequestFormPg1.Button1[0]::click - (JavaScript, both) ----------------------------



xfa.app.openDoc("http://intranet.uhhs.com/files/informationservices/computeruserregistrationclientserver.pdf");



It does not execute.



Help!



Thanks!



Melanie

Avatar

Former Community Member
In the listing you indicated, I see two errors:







  1. You're attempting to access "xfa.app". "app" is not a property of the xfa object. Rather, it's a special object made available in your JavaScript scripts simply because your scripts are executed within the context of Acrobat's JavaScript Engine. Therefore, you have access to the global "app" object that it exposes. So your statement should simply be



    app.openDoc("http://intranet.uhhs.com/files/informationservices/computeruserregistrationclientserver.pdf");





  2. You've specified that your script is to run both at client and server (based on the
    both keyword in the script header). This command can't execute at the
    server side. It can only execute on the
    client side.







Try fixing those issues and let me know if it works.



Stefan

Adobe Systems

Avatar

Former Community Member
Stefan --



Still no luck! It will not execute when I click on the button.



I feel like an idiot!



Melanie

Avatar

Former Community Member
Melanie,



We've all had moments like these. In the end, it's always a simple detail that's being overlooked. Let's keep digging until we figure it out.



I'm questioning the fact that you're using app.openDoc to open a PDF which is online (via a URL instead of a path to a file on your local drive or on a server).



The first thing you should do is change the path to point to a PDF on your local file system. This should definitely work with:



app.openDoc("myFile.pdf");


If that works, then it may be that opening a PDF file on a web server using the app.openDoc method is only possible if the web server supports WebDAV. If that's the case, you would need to do the following:



var sURL = encodeURI("http://intranet.uhhs.com/files/informationservices/computeruserregistrationclientserver.pdf");

app.openDoc({cPath: sURL, cFS: "CHTTP"});


If the web server doesn't support WebDAV, then you probably have no choice but to use the app.launchURL and open the PDF in the system's default web browser.



Let me know what you find out.



Stefan

Adobe Systems

Avatar

Former Community Member
Stefan --



You are correct -- we all have these moments. Well, I figured it out!! I switched the action from "click" to "enter" and all the links launch correctly.



Thank you, thank you, thank you for all of your help!



Melanie

Avatar

Former Community Member
I have a question for you linking folks:



I had a Word2000 document that had links to specific points of a page--essentially a pinpoint spot that I could go to. However, in the converted file the .pdf simply opens to the top of the page, which forces the reader to scroll down to the specific point.



Is there a way I can get to a specific point?

Avatar

Former Community Member
Have you looked at post #6 in this thread? I believe that would help you out with what you're trying to accomplish.



Stefan

Adobe Systems

Avatar

Former Community Member
Thank you for pointing it out. (^. ^;) I think the difficulty is more in my understanding it: Whenever I actually have to type in code my fingers sieze up and my hindbrain desires to have a magic button.

Avatar

Former Community Member
I understand. I'll be happy to help you with any questions you might have.



Stefan

Adobe Systems

Avatar

Former Community Member
Thank you!



Then, is there a machine way to have these specific destinations maintained? I've since edited my document a bit and so any that were at the bottom of the page have been moved to the next page, but for a crisper presentation I'd like to see if my box can do the work.



Or, do I have to use code for each link? In a document with over a hundred this could get a little repetitive!



Someone mentioned Named Destinations, but the help documentation doesn't seem to include information for the software handling it...