Tutorial Ebase Bookmark
Tutorial Ebase Bookmark
Contents
Prerequisites ............................................................................................................... 3
Developer Audience ............................................................................................. 3
Supported Environments ...................................................................................... 3
Overview .................................................................................................................... 3
Purpose ............................................................................................................... 3
Setup ......................................................................................................................... 3
Demo Functionalities ................................................................................................... 4
Obtaining Bookmark ............................................................................................. 4
Bookmark fields ................................................................................................... 4
Add Bookmark ..................................................................................................... 5
Delete Bookmark.................................................................................................. 6
Set Bookmark Color.............................................................................................. 7
Set Bookmark Font Style ...................................................................................... 7
Set Bookmark Title ............................................................................................... 7
2
Foxit PDF DLL SDK
Ebase Bookmark Demo
Prerequisites
Developer Audience
This document is targeted towards C/C++ developers using the Foxit PDF DLL SDK. It
assumes the developer is familiar with C/C++ and Microsoft Foundation Classes (MFC).
Supported Environments
Overview
Purpose
This document covers how to use the Foxit PDF DLL SDK’s bookmark editing module. It
uses the demo provided by Foxit Corporation as reference for explanation.
Setup
1) Download these two items from Foxit:
a. Evaluation version of the Foxit PDF DLL SDK
b. The Visual C++ 6.0 Demo
2) Extract both .zip files. Move fpdfsdk.dll and fpfsdk.lib to <yourDemoDirectory>/bin
3) Copy <yourSdkDirectory>/includes/*.h to <yourDemoDirectory>/includes,
overwriting all .h’s. You may encounter errors in building the demo if this is
not done
4) Open examples.dsw with Visual Studio 6.0
5) Compile “Ebase_Bookmark” project demo
3
Foxit PDF DLL SDK
Ebase Bookmark Demo
Demo Functionalities
The following sections contain references to the “Ebase_Bookmark” demos.
Obtaining Bookmark
When the Bookmark demo first opens a PDF file is opened with OpenPdfFile, the bookmark
content of the file should be displayed on the left panel. Inside
CEbase_BookmarkDlg::OpenPdfFile(), it first opens the document:
m_pDoc= FPDF_LoadDocument(m_PdfPath,NULL); // a FPDF_DOCUMENT object
if (m_pDoc)
m_TreeCtrl.SetTreeData(m_pDoc);
FPDF_LoadPdfDocument() opens the document and we save the document handle for
future use. We then call setTreeData(). Inside setTreeData() we call functions to get the
bookmarks:
FPDF_BOOKMARK bookmark1 = NULL;
//...
bookmark1 = FPDFBookmark_GetFirstChild(m_pDoc, NULL);
Bookmark Fields
Bookmarks have several related fields: Title, Action, and Destination.
4
Foxit PDF DLL SDK
Ebase Bookmark Demo
CBookmarkTree:GetBookmarkTitle() :
FPDFBookmark_GetTitle() – called inside to get the bookmark title.
CBookmarkTree::insertChilditem() :
FPDFBookmark_GetAction() – called to get a FPDF_ACTION object (the bookmark’s
designated action)
FPDFAction_GetDest() – called to get a FPDF_DEST object (the action’s destination
inside the PDF).
FPDFDest_GetPageIndex() – called to get the page number of page for the
FPDF_DEST object.
FPDFDest_GetZoomMode() – called to get the zoom mode for the FPDF_DEST object.
FPDFDest_GetZoomParam() – called to get the zoom parameter for the FPDF_DEST
object.
Add Bookmark
Bookmarks can do several things: Go to a certain page in the file, launch another file, open
an URI in your application (i.e. an URL in browser), or go to a remote area (could be in the
same file or in another file).
Delete Bookmark
Delete a bookmark inside a PDF document with FPDFBookmark_DeleteBookmark(). In
CBookmarkTree::DeleteBookmark(), FPDF_Bookmark_DeleteBookmark() is called with the
FPDF_DOCUMENT object and the FPDF_BOOKMARK object.
6
Foxit PDF DLL SDK
Ebase Bookmark Demo
CBookmarkTree:SetItemColor():
ColorFont_BMDict cf;
this->GetItemDict(hItem,cf); //obtain the dict object that contains the
bookmark object
BYTE a,r,g,b;
FPDFBookmark_SetColorRef(cf.pDict,color);
DWORD dr = FPDFBookmark_GetColorRef(cf.pDict);
r = GetRValue(dr);
g = GetGValue(dr);
b = GetBValue(dr);
7
Foxit PDF DLL SDK
Ebase Bookmark Demo
this->GetItemDict(hItem,cf);
if (cf.pDict)
{
BOOL bRet = FPDFBookmark_SetTitle(cf.pDict,title);
if (bRet)
{
this->SetItemDict(hItem,cf.pDict);
this->SetItemText(hItem,title);
}
return bRet;
}
return FALSE;
}
Get a bookmark’s title with FPDFBookmark_GetTitle(). Note the preparation of the buffer
for write.