cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Creating PDF Named Destinations using attribute value - Styler/APP

tcarano
1-Newbie

Creating PDF Named Destinations using attribute value - Styler/APP

I need to be able to created destinations in my PDF output that are named based on the value of the ID attribute. In Styler with the APP engine, named destinations are created by creating a hash of the current node's path and then converting it to a string:

$var hash = application.calculateHash( currentNode.getNodePath( 1 ));<>

$var linkName = "links:link" + hash.toString( 16 );<>

I need to be able to control the name of the destination using an attribute (the ID attribute) so that I can link to it from a different PDF document.

Named destinations are different from bookmarks in that they allow you to link to them from an external location (website, PDF file, etc.), and they will open to the specific page of the destination. The link works like this: [filePath]/[pdfFileName]#[namedDestination].

The code specified above is found in the APP library [installPath]\app\libs\APPStyler\app.3ns in multiple locations.

Has anyone worked within Styler OR using the library above to create a customization that support PDF destinations that are named according to an attribute value? Or does anyone have any suggestions for how to do this?

Any help or suggestions would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

The code you posted effectively generates a unique ID for each node in the document. This allows any node to be referenced, if you know its path.

I have had inter-PDF links working but it has been many years since so my memory is hazy. Regarding the using the ID instead of a hash, you could try something like this:

// leave existing code as-is

var hash = application.calculateHash( currentNode.getNodePath( 1 )); var linkName = "links:link" + hash.toString( 16 );

// new code could add a second set of links

linkName = "links:idlink" + formatting.getAttribute("id", false);

If you use that approach you will have a second set of links which are referencable via links:idlinkABC123 where ABC123 is the ID attribute value. You might have to do some work on translating the ID attribute value so it forms an allowable APP tag name. e.g. A-z 0-9 _ -

View solution in original post

5 REPLIES 5

The code you posted effectively generates a unique ID for each node in the document. This allows any node to be referenced, if you know its path.

I have had inter-PDF links working but it has been many years since so my memory is hazy. Regarding the using the ID instead of a hash, you could try something like this:

// leave existing code as-is

var hash = application.calculateHash( currentNode.getNodePath( 1 )); var linkName = "links:link" + hash.toString( 16 );

// new code could add a second set of links

linkName = "links:idlink" + formatting.getAttribute("id", false);

If you use that approach you will have a second set of links which are referencable via links:idlinkABC123 where ABC123 is the ID attribute value. You might have to do some work on translating the ID attribute value so it forms an allowable APP tag name. e.g. A-z 0-9 _ -

This worked beautifully. It successfully grabs the value of the ID attribute on the parent nodes of titles. My next challenge is to figure out test for the presence of a value for ID regardless of whether the current node is a title or not.

One thing to note is that it doesn't actually produce two sets of destinations because the definition of linkName is replaced. That's what I wanted to happen anyway, so it wasn't a problem for me.

Thanks so much for your help!

To test if there is no ID attribute, could be something like:

if (!formatting.getAttribute("id"))

{//do this};

To test it's value just pass it to a var and then the usual javascript methods apply for example:

var myAttr = formatting.getAttribute("id");

if (myAttr == 'yes') {//do this}

else if (myAttr => 10) {//do that}

I just discovered that none of the links in my document are working now (internal or external). When I restore the original code, the links work fine, but they are broken with the custom code.

Any ideas as to why this is happening?

You didn't post the full code for the method but in the original case linkName was being used to build the links, presumably by adding them to the document with FOM methods.

You basically need a second variable e.g. "linkName2" for the extra ID links, and at the bottom of the method where it adds the linkName to the document, get it to also add linkName2.

Top Tags