Page 1 of 1

Batch merging & bookmarking

Posted: Sat Dec 30, 2006 10:28 am
by marisoft

I would like to run a batch job converting a number of word-files to pdf, merging these and at the same time make bookmarks.
The bookmarls would be two level deep with the text provided by the database that holds the description and filenames of the word docs.

I have looked at using the Office Inside funtionality to do this convertion.

Is this possible ?

Any hints of how I would go about merging and bookmarking ?

Cheers and happy new year,

Posted: Sat Dec 30, 2006 12:56 pm
by Tracker - Clarion Support
Hi Poul!

Yes, I think that this is quite doable, but will involve some hand-coding to achieve.

For example, I have 3 files to be assembled: a.doc having 7 pages, b.doc having 10 pages, and c.doc having 5 pages. Within the final PDF, a.doc will occupy pages 1-7; b.doc pages 8-17; and c.doc pages 18-22. It's these PDF page numbers that your Bookmarks need to reference. If your intention is to have Bookmark point to the first page of each group, this is simple to achieve.

Bookmarks must be assigned by page number. We handle that using an object of the PDFBookmarkClass. This should be set up using FinalBkMks.Init() before the batch loop. Also create two objects of the PDFManagerClass; one to be used hold the final document, and a second to process the individual temp PDFs. For example:

Code: Select all

FinalBkMks PDFBookmarkClass
FinalPDF   PDFManagerClass
WorkPDF    PDFManagerClass
PageOffset LONG(0)
Within your loop, you will generate a PDF file for each Word document using the PDF-XChange Driver OI interface. shows how to do this. The critical thing here is to wait for the EVENT:PDF3DRV_DocSaved which signals that the PDF-XChange Driver processing is complete.

Once you have the PDF file, call WorkPDF.Init() and then WorkPDF.ReadDocument() to open the saved PDF. Use FinalBkMks.AddBookmarkRecord(STRING pTitle, LONG pPageNo, LONG pLevel) to add your Bookmarks based on your database information, adjusting any page numbers from the db to reflect the page position in the FinalPDF. pTitle holds the text string for the Bookmark, and pLevel contains the bookmark level starting with 1. Then use the WorkPDF.PagesNumber() method to return the page count for that PDF, and add it to your PageOffset to adjust the page numbers of the next PDF. Finally use FinalPDF.Merge(WorkPDF). Called with only the WorkPDF parameter, this will append all pages from WorkPDF to the end of FinalPDF. At this point you should call WorkPDF.Kill() to close the input PDF, but do NOT delete the temporary PDF file at this point! Save the names of these files in a list to be deleted after the FinalPDF is written.

After processing all files, call:

Code: Select all

FinalBkMks.AddBookmarksToPDF(FinalPDF) !to add the bookmarks
FinalPDF.WriteDocument(PdfFileName)    ! to save the final PDF file
At this point run a loop to delete the temporary PDF files and you're done!

Posted: Sat Dec 30, 2006 3:54 pm
by marisoft
Thanks for your reply.

I will have a go at it.