DynaPDF Manual - Page 121

Previous Page 120   Index   Next Page 122

Function Reference
Page 121 of 818
Return values:
If the function succeeds the return value is the handle of the bookmark, a value greater or equal
zero. If the function fails the return value is a negative error code.
Example (C++):
#include "dynapdf.h"
using namespace DynaPDF;
// first we declare an error callback function
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode, const char*
ErrMessage, SI32 ErrType)
{
printf("%s\n", ErrMessage); // just display the error message
return 0;
}
int main(int argc, char* argv[])
{
void* pdf = pdfNewPDF();
if (!pdf) return 2;
pdfSetOnErrorProc(pdf, NULL, PDFError);
pdfCreateNewPDF(pdf, "c:\cppout.pdf");
pdfAppend(pdf);
// we store the font handle, so that we can use pdfChangeFont() later
SI32 f = pdfSetFont(pdf, "Arial", fsItalic, 40, true, cp1252);
pdfWriteFText(pdf, taCenter, "How to create an outline tree...");
pdfEndPage(pdf);
// we create a few dummy pages to test the bookmarks
char s[30];
for (i = 0; i < 7; i++)
{
pdfAppend(pdf);
pdfChangeFont(pdf, f); // set the font with same parameters
sprintf(s, "Page %d", i+2);
pdfWriteFText(pdf, taLeft, s);
pdfEndPage(pdf);
}
// The first item is always a root node, Parent must be -1.
SI32 bmk = pdfAddBookmark(pdf, "First root node", -1, 1, true);
pdfAddBookmark(pdf, "1. sub node", bmk, 2, false);
pdfAddBookmark(pdf, "2. sub node", bmk, 3, false);
pdfAddBookmark(pdf, "3. sub node", bmk, 4, false);
bmk = pdfAddBookmark(pdf, "Closed sub node", bmk, 5, false);
pdfAddBookmark(pdf, "1. sub node", bmk, 6, false);
pdfAddBookmark(pdf, "2. sub node", bmk, 7, false);
bmk = pdfAddBookmark(pdf, "Closed root node", -1, 1, false);
pdfAddBookmark(pdf, "1. sub node", bmk, 4, false);
pdfAddBookmark(pdf, "2. sub node", bmk, 8, false);
 

Previous topic: AddBookmark

Next topic: AddBookmarkEx


Start Chat