Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Foxit PDF DLL SDK

Tutorial – Ebase Object Demo


Foxit PDF DLL SDK
Ebase Object Demo

Contents
Prerequisites ............................................................................................................... 3
Developer Audience ............................................................................................. 3
Supported Environments ...................................................................................... 3
Overview .................................................................................................................... 3
Purpose ............................................................................................................... 3
Setup ......................................................................................................................... 3
Demo Functionalities ................................................................................................... 4
Document ............................................................................................................ 4
Create PDF.................................................................................................... 4
Load PDF ...................................................................................................... 4
Save PDF ...................................................................................................... 4
Close PDF ..................................................................................................... 5
Page .................................................................................................................... 5
Obtain Page Objects ...................................................................................... 5
MediaBox Usage ............................................................................................ 6
CropBox Usage .............................................................................................. 7
Rotation ........................................................................................................ 7
Object ................................................................................................................. 8
Add Text Object............................................................................................. 8
Add Path Object ........................................................................................... 13
Add Image ................................................................................................... 16
Transform Objects ........................................................................................ 18
Delete Objects.............................................................................................. 19
Set Clip ........................................................................................................ 19
Remove Clip ................................................................................................. 20
Object Properties ................................................................................................ 20

2
Foxit PDF DLL SDK
Ebase Object 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

Platform Operating System Compiler

Windows (32-bit) Windows 2000/XP or later Microsoft Visual Studio 6.0.

Overview

Purpose
This document covers how to use the Foxit PDF DLL SDK’s editing PDF using objects
mechanism. 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_Objects” project demo

3
Foxit PDF DLL SDK
Ebase Object Demo

Demo Functionalities
The following sections contain references to the “Ebase_Object” demo.

Document

Create PDF

Create PDF with FPDF_CreateNewDocument(), then create pages in the document with
FPDFPage_New().
void CEbase_ObjectDlg::OnBtnCreatePdf()
{
if(m_pPDFDoc == NULL)
{
m_pPDFDoc = FPDF_CreateNewDocument();
m_pCurPage = FPDFPage_New(m_pPDFDoc,0,500,600);
//...
}
}

Load PDF

Load PDF with FPDF_LoadDocument().


void CEbase_ObjectDlg::OnBtnLoadPdf()
{
//…
CString strPDFName = dlg.GetPathName();
m_pPDFDoc = FPDF_LoadDocument(strPDFName, NULL);
//...
}

Save PDF

Save the PDF document with FPDF_SaveAsFile().Use FPDFPage_GenerateContent() to


generate content of the page you’ve modified. FPDFPage_GenerateContent() must be
called before saving a page or reloading the page, or else your changes will be lost.
void CEbase_ObjectDlg::OnBtnGeneratePdf()
{

4
Foxit PDF DLL SDK
Ebase Object Demo

if(m_pPDFDoc != NULL)
{
//...
if (dlg.DoModal() == IDOK)
{
FPDFPage_GenerateContent(m_pCurPage);
CString strPDFName = dlg.GetPathName();
int ret =
FPDF_SaveAsFile(m_pPDFDoc,strPDFName.GetBuffer(strPDFName.GetLength()),NULL,
NULL,0,NULL,0);
}
//...
}
}

Close PDF

Close PDF with FPDF_CloseDocument().


void CEbase_ObjectDlg::ClosePDF()
{
//...
if (m_pCurPage != NULL)
if (m_pPDFDoc != NULL)
{
FPDF_CloseDocument(m_pPDFDoc);
m_pPDFDoc = NULL;
}
//...
}

Page

Obtain Page Objects

Use FPDF_LoadPage() to load a page. FPDF_LoadPage() provides a FPDF_Page object. The


demo implemented four different functions
void CEbase_ObjectDlg::OnBtnFirst()
{
//...
m_pCurPage = NULL;

5
Foxit PDF DLL SDK
Ebase Object Demo

m_nCurPageNum = 0;//go to first page


m_pCurPage = FPDF_LoadPage(m_pPDFDoc, m_nCurPageNum);
//...
}

void CEbase_ObjectDlg::OnBtnPrev()
{
//...
m_pCurPage = NULL;
m_nCurPageNum -= 1;//go to previous page
m_pCurPage = FPDF_LoadPage(m_pPDFDoc, m_nCurPageNum);
//...
}

void CEbase_ObjectDlg::OnBtnNext()
{
//...
m_pCurPage = NULL;
m_nCurPageNum += 1;//go to next page
m_pCurPage = FPDF_LoadPage(m_pPDFDoc, m_nCurPageNum);
//...
}

void CEbase_ObjectDlg::OnBtnLast()
{
//...
m_pCurPage = NULL;
m_nCurPageNum = m_nTotalNum -1; // go to last page
m_pCurPage = FPDF_LoadPage(m_pPDFDoc, m_nCurPageNum);
//...
}

MediaBox Usage

MediaBox usage is done by calling FPDFPage_GetRectangle() and


FPDFPage_setRectangle(). Get rectangle grabs the current MediaBox of the page (using
FPDF_RECT_MEDIABOX). The MediaBox area, by default, contains all the PDF objects. You
can set a different MediaBox with FPDF_SetRectangleCall(), in which case it means that
you are ignoring all the objects outside of the box.
void CEbase_ObjectDlg::OnBtnPageSize()
{
//...
6
Foxit PDF DLL SDK
Ebase Object Demo

double left,right,bottom,top;
FPDFPage_GenerateContent(m_pCurPage);
FPDFPage_GetRectangle(m_pCurPage, FPDF_RECT_MEDIABOX,
&left, &right, &bottom, &top);

//update box parameters


FPDFPage_SetRectangle(m_pCurPage, FPDF_RECT_MEDIABOX,
left,right/2, bottom, top/2);
//...
}

CropBox Usage

CropBox usage is also done by calling FPDFPage_GetRectangle() and


FPDFPage_setRectangle(). CropBox represent the region of the PDF to be clipped, then
displayed. It almost all the time falls within the MediaBox, however if the CropBox were to
fall outside of the MediaBox, the objects that are within the CropBox but NOT in the
MediaBox will not be displayed.
void CEbase_ObjectDlg::OnBtnCrop()
{
//...
FPDFPage_GetRectangle(m_pCurPage, FPDF_RECT_CROPBOX,
&left, &right, &bottom, &top);

FPDFPage_SetRectangle(m_pCurPage, FPDF_RECT_CROPBOX,
left-50,right-50, bottom-50, top-50);
//...
}

Rotation

Use FPDFPage_SetRotation() to change the rotation of the page. One of following values
will be set for the rotation flag: 0(0 degree), 1(90 degrees), 2(180 degrees), 3(270
degrees)
void CEbase_ObjectDlg::OnBtnRotation()
{
//...
FPDFPage_SetRotation(m_pCurPage,m_nRotation+1);
//...
}

7
Foxit PDF DLL SDK
Ebase Object Demo

Object

Add Text Object

There are two ways to add text object with font: adding a TrueType font, and adding a
PDF-standard supported font. Adding TrueType font requires the use of FPDFLOGFONT
object, but adding PDF-Standard font does not. OnBtnAddText() shows the call order of
our functions to add these text objects:
void CEbase_ObjectDlg::OnBtnAddText()
{
//adding TrueType font
FPDF_PAGEOBJECT textobj = FPDFPageObj_NewTextObj();

FPDFLOGFONT LogFont1 ;//prepare the FPDFLOGFONT object


memset(LogFont1.lfFaceName, 0, 32);
char FontNameCH[] = "SimSun";
strcpy(LogFont1.lfFaceName, FontNameCH);
LogFont1.lfCharSet &= 0x00;
LogFont1.lfCharSet |= GB2312_CHARSET;
LogFont1.lfItalic &= 0x00;
LogFont1.lfWeight &= 0x00;
LogFont1.lfPitchAndFamily &= 0x00;

//get font object


FPDF_FONT pFont = FPDFFont_AddTrueType(m_pPDFDoc,&LogFont1);
if (!pFont)
return;
//set the parameters of the text object
FPDFTextObj_SetFont(textobj, pFont, 50);
FPDFTextObj_SetMatrix(textobj, 1, 0.5, 0, 1, 10, 100);
FPDFPageObj_SetFillColor(textobj, 0xFFFF0000);
FPDFPageObj_SetStrokeColor(textobj, 0xFF0000FF);
FPDFTextObj_SetTextMode(textobj, FPDF_TEXTMODE_FILLANDSTROKE);
FPDFTextObj_SetCharSpace(textobj,-5);
FPDFTextObj_SetWordSpace(textobj,-20);

wchar_t text[] = L"DeFont:T";


int nCount = wcslen(text);
FPDFTextObj_Insert(textobj,text,nCount,0);//add the text

//perform the insert. Note that for a form inside PDF and no form inside PDF
8
Foxit PDF DLL SDK
Ebase Object Demo

//the function used is different


if(m_bFormPage == FALSE)
{
FPDFPage_InsertObject(m_pCurPage,textobj);
}
else
{
FPDFFormObj_InsertSubObject(m_pCurPage,textobj);
}

//adding a PDF-supported font


//no need for FPDFLOGFONT
pFont = FPDFFont_AddStandardFont(m_pPDFDoc,"Helvetica",FPDF_ENCODING_WINANSI);

if (!pFont)
return;

wchar_t text1[] = L"DeFont:T";


int nCount1 = wcslen(text1);
FPDF_PAGEOBJECT textobj1 = FPDFPageObj_NewTextObjEx(text1,nCount1,pFont);
if(m_bFormPage == FALSE)
{
FPDFPage_InsertObject(m_pCurPage,textobj1);
}
else
{
FPDFFormObj_InsertSubObject(m_pCurPage,textobj1);
}
//set the parameter of the text object. It doesn’t have to be before the
//insertion to the page
FPDFTextObj_SetFont(textobj1, pFont, 40);
FPDFTextObj_SetTextMode(textobj1, FPDF_TEXTMODE_FILLANDSTROKE);
FPDFTextObj_SetCharSpace(textobj1,10);
FPDFTextObj_SetWordSpace(textobj1,20);
FPDFPageObj_SetFillColor(textobj1, 0xFFFF0000);
FPDFPageObj_SetStrokeColor(textobj1, 0xFF0000FF);
FPDFPageObj_Transform(textobj1,1,0,0,1,10,300);
//...
}

Insert Text

Insert text into text objects with FPDFTextObj_Insert().


9
Foxit PDF DLL SDK
Ebase Object Demo

void CEbase_ObjectDlg::OnBtnInsertText()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj= FPDFPage_GetObject(m_pCurPage, i);
}
else
{
page_obj=FPDFFormObj_GetSubObject(m_pCurPage,i);
}

if (page_obj)
{
int type = FPDFPageObj_GetType(page_obj);
if(type == FPDF_PAGEOBJ_TEXT)
{
wchar_t text[] = L"MM";
int nCount = wcslen(text);
int nNewCharCount = FPDFTextObj_Insert(page_obj,text,nCount,0);
}
}
//...
}

Set Unicode Text

Set unicode characters in a text object with FPDFTextObj_SetUnicode().


void CEbase_ObjectDlg::OnBtnSetunnicodeText()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj= FPDFPage_GetObject(m_pCurPage, i);
}
else

10
Foxit PDF DLL SDK
Ebase Object Demo

{
page_obj=FPDFFormObj_GetSubObject(m_pCurPage,i);
}
if (page_obj)
{
int type = FPDFPageObj_GetType(page_obj);
if(type == FPDF_PAGEOBJ_TEXT)
{
BOOL bTrueOrFal =
FPDFTextObj_SetUnicode(page_obj,0,0X004B);//0X004B is unicode for char "K"
}
}
//...
}

Delete Text

Delete text from Text objects with FPDFTextObj_Delete().


void CEbase_ObjectDlg::OnBtnDeleteText()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj= FPDFPage_GetObject(m_pCurPage, i);
}
else
{
page_obj=FPDFFormObj_GetSubObject(m_pCurPage,i);
}
if (page_obj)
{
int type = FPDFPageObj_GetType(page_obj);
if(type == FPDF_PAGEOBJ_TEXT)
{
//if (FPDFTextObj_CountChars(page_obj)>=1)
{
int nCount= FPDFTextObj_Delete(page_obj,0,1);
}
}

11
Foxit PDF DLL SDK
Ebase Object Demo

}
//...
}

Replace Text

Replace text in a text object with FPDFTextObj_Replace()


void CEbase_ObjectDlg::OnBtnReplaceText()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj= FPDFPage_GetObject(m_pCurPage, i);
}
else
{
page_obj=FPDFFormObj_GetSubObject(m_pCurPage,i);
}
if (page_obj)
{
int type = FPDFPageObj_GetType(page_obj);
if(type == FPDF_PAGEOBJ_TEXT)
{
wchar_t text2[] = L"ont:";
int nCount = wcslen(text2);

wchar_t text3[] = L"NNNN";


int nCount1 = wcslen(text3);
if (FPDFTextObj_Find(page_obj,text2,nCount) != -1)
{
int nNewCharCount =
FPDFTextObj_Replace(page_obj,text2,nCount,text3,nCount1);
}
}
}
//...
}

12
Foxit PDF DLL SDK
Ebase Object Demo

Compare Text

Compare text with text from a text object with FPDFTextObj_compare


void CEbase_ObjectDlg::OnBtnCompareText()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj= FPDFPage_GetObject(m_pCurPage, i);
}
else
{
page_obj=FPDFFormObj_GetSubObject(m_pCurPage,i);
}
if (page_obj)
{
int type = FPDFPageObj_GetType(page_obj);
if(type == FPDF_PAGEOBJ_TEXT)
{
wchar_t text4[] = L"DeFNNNNT";
int nCount = wcslen(text4);
//compare
BOOL bEqual = FPDFTextObj_Compare(page_obj,text4,nCount);
if (bEqual)
AfxMessageBox("Compare \"DeFNNNNT\" success!");
else
AfxMessageBox("Compare \"DeFNNNNT\" failure!");
}
}
//...
}

Add Path Object

OnBtnAddPath() shows the function order to add path object to a PDF page.
void CEbase_ObjectDlg::OnBtnAddPath()
{
FPDF_PAGEOBJECT path_obj = FPDFPageObj_NewPathObj();

13
Foxit PDF DLL SDK
Ebase Object Demo

FPDFPageObj_SetStrokeColor(path_obj, 0xFF00FFFF);//set the stroke color


FPDFPageObj_SetFillColor(path_obj, 0xFF0000FF);//set the fill color

double dbPointX[4] = {0, 100, 300,400};


double dbPointY[4] = {0, 100, 700,400};
int flags[4] = {FPDF_PATH_MOVETO, FPDF_PATH_BEZIERTO,
FPDF_PATH_BEZIERTO,FPDF_PATH_BEZIERTO};
//set the points of the path object
FPDFPathObj_SetPoints(path_obj, 4, dbPointX, dbPointY, flags);

//getter examples: FPDFPathObj_GetStroke(),FPDFPathObj_GetFillMode(), etc.


BOOL bStroke = FPDFPathObj_GetStroke(path_obj);
int iFillMode = FPDFPathObj_GetFillMode(path_obj);
DWORD dwColor =FPDFPageObj_GetFillColor(path_obj);

//Set fill stroke and dashes


FPDFPathObj_SetFillStroke(path_obj, FPDF_FILL_ALTERNATE, 1);
FPDFPageObj_SetDashCount(path_obj, 10);
int nDashCount = FPDFPageObj_GetDashCount(path_obj);
for(int i = 0; i<nDashCount; i += 1)
FPDFPageObj_SetDashArray(path_obj, i, 4);
double value = FPDFPageObj_GetDashArray(path_obj, 2);

//set line parameters


double width = FPDFPageObj_GetLineWidth(path_obj);
FPDFPageObj_SetLineWidth(path_obj, width + 3);

//insert points to the path object.


FPDFPathObj_InsertPoint(path_obj, 0, 0, FPDF_PATH_MOVETO, 0);
FPDFPathObj_InsertPoint(path_obj, 100, 100, FPDF_PATH_LINETO, 1);
FPDFPathObj_InsertPoint(path_obj, 100, 0, FPDF_PATH_LINETO, 2);

double x = FPDFPathObj_GetPointX(path_obj, 0);


double y = FPDFPathObj_GetPointY(path_obj, 0);
FPDF_PATH path = FPDFPathObj_GetPath(path_obj);

//set and get dash phase


FPDFPageObj_SetDashPhase(path_obj, 101);
double iPhase = FPDFPageObj_GetDashPhase(path_obj);
if(m_bFormPage == FALSE)
{

14
Foxit PDF DLL SDK
Ebase Object Demo

FPDFPage_InsertObject(m_pCurPage,path_obj);
}
else
{
FPDFFormObj_InsertSubObject(m_pCurPage,path_obj);
}
//...
}

Modify Path

OnBtnModifyPath() shows several path modification functions.


void CEbase_ObjectDlg::OnBtnModifyPath()
{
//...
FPDF_PAGEOBJECT path_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE){
path_obj = FPDFPage_GetObject(m_pCurPage, i);
}else{
path_obj = FPDFFormObj_GetSubObject(m_pCurPage,i);
}

int nPointCount = FPDFPathObj_CountPoints(path_obj);


step %= 9;
if(step == 0){
FPDFPathObj_SetFillStroke(path_obj, FPDF_FILL_NULL, 1);// no fill
//...
}
if(step == 1){
FPDFPageObj_SetDashCount(path_obj, 0);//no dash
//...
}
if(step == 2){
FPDFPageObj_SetLineWidth(path_obj, 10);//set line width to 10
//...
}
if(step == 3){
FPDFPageObj_SetLineCapStyle(path_obj, 1); //round cap
//...
}

15
Foxit PDF DLL SDK
Ebase Object Demo

if(step == 4){
FPDFPageObj_SetLineJoinStyle(path_obj, 1);//join round
//...);
}
if(step == 5){
FPDFPageObj_SetLineJoinStyle(path_obj, 0); //join miter
//...
}
if(step == 6){
FPDFPageObj_SetMiterLimit(path_obj, 1);//set miter limit to 1
//...
}
if(step == 7){
FPDFPathObj_RemovePoint(path_obj, 2);//remove specific point by index
//...
}
if(step == 8){
FPDFPathObj_ClearPoints(path_obj);//remove all points
//...
}
//...
}

Add Image

Add image with FPDPageObj_newImgeObj(), FPDFImageObj_LoadFromFile(), and


FPDFImageObj_SetMatrix().
void CEbase_ObjectDlg::OnBtnAddImage()
{
//...
//create image object
FPDF_PAGEOBJECT page_obj = FPDFPageObj_NewImgeObj(m_pPDFDoc);
FPDF_PAGE Page[1];
Page[0] = m_pCurPage;
//load your image from file to the object
BOOL ret =
FPDFImageObj_LoadFromFile(Page,1,page_obj,dlg.GetPathName());
//...
//set the transform matrix for the image
FPDFImageObj_SetMatrix(page_obj,200,0,100,200,0,100);
//insert object to the page
FPDFPage_InsertObject(m_pCurPage,page_obj);
16
Foxit PDF DLL SDK
Ebase Object Demo

//...
}

Modify Image

Modify the content of an image object with FPDFImageObj_SetBitmap() or


FPDFImageObj_LoadFromFile() (see previous example). In OnBtnModifyImage(), we take
the rendered bitmap of the page as the bitmap to replace the original bitmap.
void CEbase_ObjectDlg::OnBtnModifyImage()
{
//...
pPageObj = FPDFPage_GetObject(m_pCurPage,nIndex);
if (pPageObj == NULL || FPDFPageObj_GetType(pPageObj) !=
FPDF_PAGEOBJ_IMAGE)
return;
if (pPageObj)
{
FPDF_BITMAP bmp = FPDFBitmap_Create(300,300,FPDFBitmap_BGRx);
//render a bitmap. We use the PDF page here
FPDF_RenderPageBitmap(bmp,m_pCurPage,0,0,300,300,0,FPDF_ANNOT);
FPDF_PAGE Page[1];
Page[0] = m_pCurPage;
//set the bitmap
FPDFImageObj_SetBitmap(Page,1,pPageObj,bmp);
//clean up with FPDFBitmap_Destroy()
FPDFBitmap_Destroy(bmp);
Invalidate(FALSE);
}
}

Modify Image Matrices

Modify image object matrix with FPDFImageObj_GetMatrix() and


FPDFImageObj_SetMatrix().
void CEbase_ObjectDlg::OnBtnModifymatrixs()
{
//...
pPageObj = FPDFPage_GetObject(m_pCurPage,nIndex);
if (pPageObj == NULL || FPDFPageObj_GetType(pPageObj) !=
FPDF_PAGEOBJ_IMAGE)
return;
if (pPageObj)
17
Foxit PDF DLL SDK
Ebase Object Demo

{
double a,b,c,d,e,f;
//get the matrix from the image object
FPDFImageObj_GetMatrix(pPageObj,&a,&b,&c,&d,&e,&f);
a=a*1.2;
d=d*1.2;
c=c+100;
f = f+100;
//set the new matrix, replacing the old one
FPDFImageObj_SetMatrix(pPageObj,a,b,c,d,e,f);
Invalidate(FALSE);
}
}

Transform Objects

Moving or transforming a PDF object with FPDFPageObj_Transform(). This performs a


linear transformation on the object and move/transform the object. For details on the
individual parameters of the function, please refer to fpdfeditbase.h
void CEbase_ObjectDlg::OnBtnMove()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj = FPDFPage_GetObject(m_pCurPage, i);
}
else
{
page_obj = FPDFFormObj_GetSubObject(m_pCurPage, i);
}
if (page_obj)
{
//this performs a move
FPDFPageObj_Transform(page_obj,1,0,0,1,100,0);
//this performs a shape change
FPDFPageObj_Transform(page_obj,1,0.5,0.5,1.5,0,0);
//...
}
//...
18
Foxit PDF DLL SDK
Ebase Object Demo

Delete Objects

Delete objects with FPDFPage_DeleteObject() or FPDFFormObj_DeleteSubObject().


void CEbase_ObjectDlg::OnBtnDelete()
{
//...
//different functions used for deleting object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
FPDFPage_DeleteObject(m_pCurPage,i);
}
else
{
FPDFFormObj_DeleteSubObject(m_pCurPage,i);
}
//...
}

Set Clip

Set clip region for an object by setting points on a path, then use FPDFPageObj_AddClip()
with the path to add the region. The path represents an enclosed region.
void CEbase_ObjectDlg::OnBtnSetClip()
{
//set up path
FPDF_PAGEOBJECT path_obj = FPDFPageObj_NewPathObj();
double dbPointX[4] = {150, 150, 400,400};
double dbPointY[4] = {150, 400, 400,150};
int flags[4] = {FPDF_PATH_MOVETO, FPDF_PATH_LINETO,
FPDF_PATH_LINETO,FPDF_PATH_LINETO|FPDF_PATH_CLOSEFIGURE};
FPDFPathObj_SetPoints(path_obj, 4, dbPointX, dbPointY, flags);
FPDF_PATH path = FPDFPathObj_GetPath(path_obj);

//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page

19
Foxit PDF DLL SDK
Ebase Object Demo

if(m_bFormPage == FALSE)
{
page_obj = FPDFPage_GetObject(m_pCurPage, i);
}
else
{
page_obj = FPDFFormObj_GetSubObject(m_pCurPage, i);
}
//add path as the clip region
FPDFPageObj_AddClip(page_obj, path, FPDF_FILL_NULL);
FPDFPageObj_Free(path_obj);

//...
}

Remove Clip

Remove clip region with FPDFPageObj_removeClip().


void CEbase_ObjectDlg::OnBtnRemoveClip()
{
//...
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj = FPDFPage_GetObject(m_pCurPage, i);
}
else
{

page_obj = FPDFFormObj_GetSubObject(m_pCurPage, i);


}
FPDFPageObj_RemoveClip(page_obj,0);
//...
}

Object Properties
Individual objects have different properties that you can obtain. ShowPageObjProperty()
contains example on how to obtain many of these. These correspond to the bottom of the
20
Foxit PDF DLL SDK
Ebase Object Demo

demo dialog shown.

void CEbase_ObjectDlg::ShowPageObjProperty(int nIndex)


{
//obtain the object
FPDF_PAGEOBJECT page_obj;
//different functions used for obtaining object from a form page and a
//regular page
if(m_bFormPage == FALSE)
{
page_obj = FPDFPage_GetObject(m_pCurPage, nIndex);
}
else
{
page_obj = FPDFFormObj_GetSubObject(m_pCurPage, nIndex);
}
int type = FPDFPageObj_GetType(page_obj);

//GetFillColor
FPDF_DWORD color = FPDFPageObj_GetFillColor(page_obj);
int r,g,b,a;
r = FPDF_GetRValue(color);
g = FPDF_GetGValue(color);
b = FPDF_GetBValue(color);
a = FPDF_GetAValue(color)*100/255;
//...

//GetStrokeColor
color = FPDFPageObj_GetStrokeColor(page_obj);
r = FPDF_GetRValue(color);
g = FPDF_GetGValue(color);
b = FPDF_GetBValue(color);
a = FPDF_GetAValue(color)*100/255;
//...

//GetLineWidth
int nLineWidth = FPDFPageObj_GetLineWidth(page_obj);
//...

//GetLineCap
int nLineCap = FPDFPageObj_GetLineCapStyle(page_obj);
CString strLineCap;

21
Foxit PDF DLL SDK
Ebase Object Demo

switch(nLineCap)
{
case FPDF_LINECAP_BUTT:
strLineCap = "Butt Cap";
break;
case FPDF_LINECAP_ROUND:
strLineCap = "Round Cap";
break;
case FPDF_LINECAP_PROJECT:
strLineCap = "Projecting square";
break;
default:
strLineCap = "";
break;
}
//...

//GetLineJoin
int nLineJoin = FPDFPageObj_GetLineJoinStyle(page_obj);
CString strLineJoin;
switch(nLineJoin)
{
case FPDF_LINEJOIN_MITER:
strLineJoin = "Miter Join";
break;
case FPDF_LINEJOIN_ROUND:
strLineJoin = "Round Join";
break;
case FPDF_LINEJOIN_BEVEL:
strLineJoin = "Bevel Join";
break;
default:
strLineJoin = "";
break;
}
//...

//GetMiterLimit
int nMiterLimit = FPDFPageObj_GetMiterLimit(page_obj);
//...

//GetDashCount

22
Foxit PDF DLL SDK
Ebase Object Demo

int nDashCount = FPDFPageObj_GetDashCount(page_obj);


//...

if(nDashCount >0)
{
//GetDashArray
str = "Dash Array : \n ";
for(int i = 0; i<nDashCount; i++)
{
double lfDashData = FPDFPageObj_GetDashArray(page_obj,i);
//...
}
//...

//GetDashPhase
double lfDashPhase = FPDFPageObj_GetDashPhase(page_obj);
//...
}
//...

//path only
if(type == FPDF_PAGEOBJ_PATH)
{
//GetFillMode
int nMode = FPDFPathObj_GetFillMode(page_obj);
CString strFillMode;
switch(nMode)
{
case FPDF_FILL_NULL:
strFillMode = "No fill color.";
break;
case FPDF_FILL_ALTERNATE:
strFillMode = "Alternate";
break;
case FPDF_FILL_WINDING:
strFillMode = "Winding";
break;
default:
break;
}
//...
/////GetStroke

23
Foxit PDF DLL SDK
Ebase Object Demo

BOOL bStroke = FPDFPathObj_GetStroke(page_obj);


//...

/////GetPointNumber
int nPointCount = FPDFPathObj_CountPoints(page_obj);
//...
}
//...

//text only
if(type == FPDF_PAGEOBJ_TEXT)
{
//GetTextMode
int nMode = FPDFTextObj_GetTextMode(page_obj);
CString strMode;
switch(nMode)
{
case FPDF_TEXTMODE_FILL:
strMode = "Fill";
break;
case FPDF_TEXTMODE_STROKE:
strMode = "Stroke";
break;
case FPDF_TEXTMODE_FILLANDSTROKE:
strMode = "Fill And Stroke";
break;
case FPDF_TEXTMODE_INVISIBLE:
strMode = "No Fill No Stroke";
break;
default:
break;
}
//...

//GetFontName
FPDF_FONT font = FPDFTextObj_GetFont (page_obj);
const char* pName = FPDFFont_GetFontName(font);
//...

//GetFontSize
int nSize = FPDFTextObj_GetFontSize(page_obj);
//...

24
Foxit PDF DLL SDK
Ebase Object Demo

//Get Char number


int nNum = FPDFTextObj_CountChars(page_obj);
//...

//Get Char Space


double charspace = FPDFTextObj_GetCharSpace(page_obj);
//...

//Get Word Space


double wordspace = FPDFTextObj_GetWordSpace(page_obj);
//...

//GetFontFlag
int nFlag = FPDFFont_GetFlags(font);
CString strFlag;
if(nFlag == 0)
{
strFlag = " Reserve";
}
else
{
if(FPDF_FLAG_FIXEDPITCH & nFlag)
strFlag += " FixedPitch";
if(FPDF_FLAG_SERIF & nFlag)
strFlag += " Serif";
if(FPDF_FLAG_SYMBOLIC & nFlag)
strFlag += " Symbolic";
if(FPDF_FLAG_SCRIPT & nFlag)
strFlag += " Script";
if(FPDF_FLAG_NONSYMBOLIC & nFlag)
strFlag += " NonSymbolic";
if(FPDF_FLAG_ITALIC & nFlag)
strFlag += " Italic";
if(FPDF_FLAG_ALLCAP & nFlag)
strFlag += " AllCap";
if(FPDF_FLAG_SMALLCAP & nFlag)
strFlag += " SmallCap";
if(FPDF_FLAG_FORCEBOLD & nFlag)
strFlag += " ForceBold";
}
//...

25
Foxit PDF DLL SDK
Ebase Object Demo

}
//...

//GetBBox
double left,right,bottom,top;
FPDFPageObj_GetBBox(page_obj,&left,&right,&bottom,&top);
//...

//GetMatrix
double matrix_a,matrix_b,matrix_c,matrix_d,matrix_e,matrix_f;
switch(type)
{
case FPDF_PAGEOBJ_TEXT:
FPDFTextObj_GetMatrix(page_obj,&matrix_a,&matrix_b,
&matrix_c,&matrix_d,&matrix_e,&matrix_f);
//...
break;
case FPDF_PAGEOBJ_IMAGE:
FPDFImageObj_GetMatrix(page_obj,&matrix_a,&matrix_b,
&matrix_c,&matrix_d,&matrix_e,&matrix_f);
//...
break;
case FPDF_PAGEOBJ_FORM:
FPDFFormObj_GetMatrix(page_obj,&matrix_a,&matrix_b,
&matrix_c,&matrix_d,&matrix_e,&matrix_f);
//…
break;
case FPDF_PAGEOBJ_PATH:
FPDFPathObj_GetMatrix(page_obj,&matrix_a,&matrix_b,
&matrix_c,&matrix_d,&matrix_e,&matrix_f);
//…
break;
default:
str = "Matrix : NULL";
break;
}
//…

//GetClipCount
int nClipNum = FPDFPageObj_GetClipCount(page_obj);
str.Format("Clip Count : %d",nClipNum);
//…

26
Foxit PDF DLL SDK
Ebase Object Demo

27

You might also like