Creating Unicode bookmarks
Estimated Reading Time: 2 MinutesA bookmark in a PDF document labels a place within the PDF document to serve as a destination, usually a heading or a graphic. After you add a bookmark, you can create a hyperlink elsewhere in the same PDF document and connect it to that bookmark. When the reader clicks on that link the viewer will take the reader to the page or a section of a page in the PDF where that bookmark is found. The bookmark is entered in the outline dictionary and appears on the left side of the Adobe Acrobat or Reader page.
A bookmark title needs to be in PDFDocEncoding or UTF-16BE (including the byte order marker) for Japanese or other non-Latin languages.
#define PARENTBOOKMARK "bookmark 1" #define CHILDBOOKMARK "bookmark 1.1" #define dstPageNumParent 2 #define dstPageNumChild 1 void MainProc(void); void MainProc(void) { PDBookmark parentBm, childBm, rootBm; PDAction pdActionParent, pdActionChild; PDViewDestination destParent, destChild; PDPage dstPageParent, dstPageChild; ASAtom fitType; ASFixedRect destRect = {0, Int16ToFixed(5*72), Int16ToFixed(8*72), 0}; /* Initialize mediabox */ ASFixed zoom; char buf[256]; DURING /*------------------------------------------------- Get bookmark root. Return value is valid even if bookmark root is empty. Then add new child or siblings. *------------------------------------------------*/ rootBm = PDDocGetBookmarkRoot(pdDoc1); /* Set the parent title in Unicode */ char korTitle[] = {0xFE, 0xFF, 0xB3, 0x00, 0xD5, 0x5C, 0xBB, 0xFC, 0xAD, 0x6D, 0x00, 0x00}; parentBm = PDBookmarkAddNewChild (rootBm, korTitle); /* Aquire PDPage of the bookmark destination from PDDoc */ dstPageParent = PDDocAcquirePage(pdDoc1, dstPageNumParent); /* Initialize zoom, fit type for the destination PDPage */ fitType = ASAtomFromString ("Fit"); zoom = 2; /* Create view of the destination PDPage */ destParent = PDViewDestCreate(pdDoc1, dstPageParent, fitType, &destRect, zoom, dstPageNumParent); /* Create new PDAction and set bookmark action */ if(PDViewDestIsValid(destParent)){ pdActionParent = PDActionNewFromDest(pdDoc1, destParent, pdDoc1); if (PDActionIsValid(pdActionParent)) PDBookmarkSetAction(parentBm, pdActionParent); else{ printf("Error in creating pdaction\n"); exit(-1); } } /*--------------------------------------------------- Create a child bookmark for the parent bookmark *--------------------------------------------------*/ childBm = PDBookmarkAddNewChild (parentBm, CHILDBOOKMARK); dstPageChild = PDDocAcquirePage(pdDoc1, dstPageNumChild); fitType = ASAtomFromString ("FitH"); zoom = 5; destChild = PDViewDestCreate(pdDoc1, dstPageChild, fitType, &destRect, zoom, dstPageNumChild); if(PDViewDestIsValid(destChild)){ pdActionChild = PDActionNewFromDest(pdDoc1, destChild, pdDoc1); if (PDActionIsValid(pdActionChild)) PDBookmarkSetAction(childBm, pdActionChild); else{ printf("error in creating pdaction\n"); exit(-1); } } HANDLER ...