Skip to main content
1-Visitor
November 4, 2014
Solved

Creating PDF Named Destinations using attribute value - Styler/APP

  • November 4, 2014
  • 1 reply
  • 2313 views

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!

Best answer by GarethOakes

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 _ -

1 reply

16-Pearl
November 5, 2014

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 _ -

tcarano1-VisitorAuthor
1-Visitor
November 6, 2014

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!

12-Amethyst
November 7, 2014

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}