Skip to main content
March 27, 2012
Question

Save PDF with Bookmarks

  • March 27, 2012
  • 1 reply
  • 7191 views

How to save a book as PDF with bookmarks?

I am exporting an open book as PDF using the following script:

var params = GetSaveDefaultParams()

var returnParamsp =new PropVals()

var i = GetPropIndex(params, Constants.FS_FileType)

params.propVal.ival =Constants.FV_SaveFmtPdf

file.Save(pdfName, params, returnParamsp)

This works fine but the pdf document does not have bookmarks. I would like to get the same

result as if a selected "Generate PDF bookmarks" (translated from German) on the Bookmars

page of the PDF Settings dialog.

I guess I will have to set some property value, but which one? Is there a place where I can

look it up?

Thanks

This topic has been closed for replies.

1 reply

Participating Frequently
April 10, 2012

Im surprised no one else has contributed to this question. If anyone has been able to get this to work consistently through extendscript then I would certainly be interested!

I have done this through code many times using Elmsoft Framescript, but simply cant get the process fully automated trough extendscript.

You do need more code in addition to your extract. You need to iterate through each component in the book and make sure that you set "Doc.PDFBookmark = true;" saving each component as you loop through.

In theory when you update the book it will use the PDFBookmark setting in the first component in the book to decide whether to generate the bookmarks or not. This is how it has worked in the past.

Unfortunately there seems to be a bug in the update book function in FM10 and the only way to reliably get it to set is to manually highlight the book and select "Format>Document>PDF Setup" and check the box "Generate PDF Bookmarks". Indeed if you open a component in the book and toggle the "Doc.PDFBookmark = true;" value you will see the "Generate PDF Bookmarks" checkbox toggle on and off. But unfortunately the value on the book itself seems to be read only (which was the case in the past but it would dynamically change once the book was updated after having changed the value on the document components).

An option here you might think would be to use fcodes to control the PDF Setup dialog to set the property, but alas there is an existing bug in FM10 which stops fcodes from working properly with a book (you can get the popup open but cant cant control it)! I think in all likelyhood the bug that stops fcodes from working properly is the same bug stopping the PDFBookmark functionality.

So it looks like we are stuck until Adobe issue a patch. Maybe someone out there has got this to work, if so please let us both know!

frameexpert
Community Expert
Community Expert
April 10, 2012

I have had to deal with this issue several times over the years. If you save a book file as MIF and look at it with a text editor, you will see that bookmark information is stored in the book. However, there is no way (that I know of) to programmatically reach this information with FrameScript, ExtendScript, or the FDK. The only reliable solution is to programmatically save the book as a MIF file, then parse through it and change the bookmark levels as appropriate, then open the MIF with FrameMaker and save it back to a .book file. This could all be done with ExtendScript or FrameScript, etc.

Rick Quatro

www.frameexpert.com
Participating Frequently
April 10, 2012

The only values that change in my MIF files are as follows:

 

[Old text]: "20202020203C786D703A437265617465446174653E303131322D30332D31305431343A33373A3134"

[New text]: "20202020203C786D703A437265617465446174653E303131322D30332D31305431343A33383A3533"

 

[Old text]: "64696679446174653E303131322D30332D31305431343A33373A31342B30313A30303C2F786D703A"

[New text]: "64696679446174653E303131322D30332D31305431343A33383A35332B30313A30303C2F786D703A"

[Old text]: "3131322D30332D31305431343A33373A31342B30313A30303C2F786D703A4D657461646174614461"

[New text]: "3131322D30332D31305431343A33383A35332B30313A30303C2F786D703A4D657461646174614461"

Im not sure this is what you expected.

Generating PDF files with bookmarks programmatically shouldnt be a problem at all, and i have done this without problem in FM7 & 8 using Framescript, I have the source code still on my old PC running FM7 and this is what im using to port my code to extend script.

My current extend script will open a book and loop through each component. The script will clear all headings and then set specific AcrobatLevel for page formats. Here is a code extract from my current routine:

// Clear all formats first

var count = 0;

var pgfFmt = doc.FirstPgfFmtInDoc;
while (pgfFmt.ObjectValid()) {
    count++;
     pgfFmt.AcrobatLevel = 0
    pgfFmt = pgfFmt.NextPgfFmtInDoc;
}

// Now set specific headings

  var pgfFmt = doc.GetNamedPgfFmt("Numbered Head");

    pgfFmt.AcrobatLevel = 1

   var pgfFmt = doc.GetNamedPgfFmt("Heading 1");

    pgfFmt.AcrobatLevel = 2

I set other values such as PDFBookmark and

doc.GenerateAcrobatInfo = true;



The script will save each component after the change and then update the book.

After updating the book I save as PDF.



The script will generate a PDF wihtout bookmarks (but would work in Framescript).



Here is the rub:



Before running the function to save the book as a PDF i run the following sub routine to debug (after having made the book the focused item):

function pop(){
    FcodeList = new Array(FCodes.KBD_ACROBAT_SETUP,FCodes.START_DIALOG,FCodes.KBD_RETURN,FCodes.END_DIALOG); //Fcodes
Fcodes(FcodeList); // Fcode Execution
    }



This pops up the "PDF Setup" dialog.



I close the PDF Setup dialog without making any change to the values (by clicking cancel) and the PDF generates with the bookmarks correctly in tact at the right levels.



So it would appear that there is something that takes place when the PDF Setup dialog opens that updates the book correctly. However this is not accessable from the APIs currently in FM10. A basic update book call in Framescript was sufficient in my FM7 source code.



Any other opinions out there?