Wing,
To create a hyperlink that jumps to a specific page, you would need to create the following global function in your document:
function @PDFJumpToPage(&pagenumber: integer, &caption: string, &fontheight: measure)
define(&currX,measure,¤t.x)
gsave()
setstyleext(&internal.defaultfont,&fontheight,1,[100,100,0,0],-1)
passthrough('[/Subtype /Link')
passthrough('/Rect [ '+floattostr(¤t.x*72)+' '+floattostr(¤t.y-(&fontheight*2/3))+ ' ' + floattostr((¤t.x+stringwidth(&caption))*72) + ' ' + floattostr(¤t.y+(&fontheight/3))+']')
passthrough('/Border [ 0 0 0]')
passthrough('/Page ' + inttostr(&pagenumber))
passthrough('/View [/XYZ 0 '+floattostr(¤t.pageheight*72)+' null]')
passthrough('/ANN pdfmark')
show(&caption)
grestore()
rmoveto(stringwidth(&caption),0)
endfunction()
Then, whenever you want to display a link that jumps to a specific page, you add a new PlanetPress Talk Object containing code similar to this:
@PDFJumpToPage(3,'Goto Page 3',12)
Where the first parameter is the page to jump to, the second parameter is the caption for the link, and the third parameter is the size of the font to use for displaying the link.
However, that won't address what - in my humble opinion - your real issues are: how to know on which page each of the sections begin? And then, how to add that information back to the TOC, which is usually found at the start of the document?
I have to admit having to perform a bit of research for that one, I had never tried it before. Well, it happens to be pretty simple after all! You will need to use
Named Destinations within the document, instead of absolute page numbers. And you'll need to create a global function similar to the one above, but that references those Named Destinations instead.
Here's the code for the global function:
function @PDFJumpToDest(&Destname: string, &caption: string, &fontheight: measure)
define(&currX,measure,¤t.x)
gsave()
setstyleext(&internal.defaultfont,&fontheight,1,[100,100,0,0],-1)
passthrough('[/Subtype /Link')
passthrough('/Rect [ '+floattostr(¤t.x*72)+' '+floattostr(¤t.y-(&fontheight*2/3))+ ' ' + floattostr((¤t.x+stringwidth(&caption))*72) + ' ' + floattostr(¤t.y+(&fontheight/3))+']')
passthrough('/Border [ 0 0 0]')
passthrough('/Dest /' + &Destname)
passthrough('/View [/XYZ 0 '+floattostr(¤t.pageheight*72)+' null]')
passthrough('/ANN pdfmark')
show(&caption)
grestore()
rmoveto(stringwidth(&caption),0)
endfunction()
Where the first parameter is the actual name of the destination, and the others are just like for the very first function above.
Be careful: that name is
case-sensitive, so you'll have to use the exact same name when you want to jump to it.
So let's say you already know your document will have 5 sections. You can create links on the very first page by creating 5 PlanetPress Talk Objects. They would contain something like:
%First PPTalk object
@PDFJumpToDest('MySection1','Goto Section 1',12)
...
%Second PPTalk object
@PDFJumpToDest('MySection2','Goto Section 2',12)
...
...
%Fifth PPTalk object
@PDFJumpToDest('MySection5','Goto Section 5',12)
Now all that's left is for you to actually
create those named destinations as the job is being processed. I am assuming that you have some way of knowing
when a new section begins, and
which section it happens to be. Let's say, for instance, that you have a condition named
IsNewSection which allows you to test if you are now entering a new section, and another variable named
CurrentSection that you increment every time you move to the next section.
In a PlanetPress Talk object on the physical page that begins the section, you would therefore add the following code in the PlanetPress Tak Before section of its properties:
if(&IsNewSection)
passthrough('[/Dest /MySection' + inttostr(&CurrentSection))
passthrough(' /DEST pdfmark')
&CurrentSection := &CurrentSection+1
endif()
Note how we are appending the current value stored in
CurrentSection to the named destination
/MySection (yielding, in the end,
MySection1,
MySection2, etc.)
Now, if you do all of this (and assuming there aren't too many typos in the code I posted...), you should be able to jump anywhere in your document.
Have fun!