Create bookmarks in PDF converted files

If you are a VB developer and have questions about using our products from VB, here is the place to post them.
Post Reply
mauribon
Posts: 11
Joined: Mon Oct 18 2004

Create bookmarks in PDF converted files

Post by mauribon »

I am trying to write an application in VBA for Excel 97 that prints some sheets from a XLS file to a pdf file.
The application is already working, but now I would like to create a bookmark (named as the XLS sheet) for each sheet printed in the pdf. Is it possible to obtain this?

Here is the code:

Option Explicit
Const AMY_USER = "Evaluation Version Pro"
Const AMY_SERIAL = "07EFCDAB0100010020E5DB96D44F811C57E4A57B87646F5868226931E3C093AFD2E3DF34B886A8658D278AAF565A4D4CC127834D4DC892A0BE16BAD545D09D3A90D1410B31A22A81C7D6C466DF90A406C040A6"

Const NoPrompt As Integer = 1 ' do not prompt for file name
Const UseFileName As Integer = 2 ' use file name set by SetDefaultFileName else use document name
Const Concatenate As Integer = 4 ' concatenate files, do not overwrite
Const DisableCompression As Integer = 8 ' disable page content compression
Const EmbedFonts = 16 ' embed fonts used in the input document
Const BroadcastMessages = 32 ' enable broadcasting of PDF events

Sub PrintToPDF(sFilePDF As String, ParamArray aFogli())
'********************************
'** Stampa il documento su PDF **
'********************************
Dim PDFPrinter As New CDIntfEx.CDIntfEx
Dim dc As OLE_HANDLE

' this adds a new printer named PrtReltec
PDFPrinter.PDFDriverInit "PrtReltec"
dc = PDFPrinter.CreateDC

PDFPrinter.EnablePrinter AMY_USER, AMY_SERIAL
PDFPrinter.PaperSize = 9 ' set paper size to A4
PDFPrinter.Orientation = 1 ' portrait
PDFPrinter.SetDefaultPrinter ' set printer as default

PDFPrinter.DefaultFileName = sFilePDF ' set default file name
PDFPrinter.FileNameOptions = NoPrompt + UseFileName + Concatenate ' set options

'** Stampa tutti i fogli passati come parametro **
For i = 0 To UBound(aFogli)
Worksheets(aFogli(i)).PrintOut ActivePrinter:="PrtReltec"
PDFPrinter.SetBookmark dc, 0, aFogli(i) <- THIS CAN'T WORK !!!
Next

PDFPrinter.FileNameOptions = 0 ' reset all options before returning
PDFPrinter.DriverEnd
Set PDFPrinter = Nothing ' also removes the PDF printer
End Sub
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Post by Jose »

Hello,

Unfortunately this type of procedure is not possible with the PDF Converter because the device context (DC) created in one application can not access the device context (DC) of another application.

In order to resolve this issue I suggest that you look at our product the PDF Creator. This product gives you the ability to create bookmarks on existing PDF documents.

Thanks
mauribon
Posts: 11
Joined: Mon Oct 18 2004

Post by mauribon »

I have created the bookmarks using the setBookmark metod of the document object (pdfconverter), but it can't create the sublevels.
Thank you.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

When calling SetBookmark you can use the following for the Level parameter:
0: inserts the bookmark at the same level of previous bookmark
1: inserts the bookmark at child level of previous one
-1: inserts the bookmarks at parent level of previous one
you can also use values like 2 or -2 depending on where you are in the bookmarks tree.

Hope this helps.
mauribon
Posts: 11
Joined: Mon Oct 18 2004

Post by mauribon »

I have tried to set the Level parameter to 1, but the bookmark is missing.
With the parameter = 0 it works.
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

Please post the code you are using to add bookmarks to the pdf file after it is generated.

a sample code will do.

Thanks.
Post Reply