Skip to content

PDF Page

A PDF page is a fundamental and essential part of a PDF document. Use PDFDoc.getPage to obtain a PDFPage object from a document. Page-level APIs support parsing, rendering, and editing pages (including create, delete, flatten, and more), retrieving PDF annotations, and getting and setting page properties. In most cases, a page must be parsed before it is rendered or processed.

Get Page Dimensions

c++
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace common;
using namespace pdf;
...
// Assuming PDFPage page has been loaded and parsed.

int width = static_cast<int>(page.GetWidth());
int height = static_cast<int>(page.GetHeight());
C
#include "include/fs_basictypes_c.h"
#include "include/fs_pdfpage_c.h"
...
// Assuming FS_PDFPAGE_HANDLE page has been loaded and parsed.

float fWidth;
float fHeight;
FSDK_PDFPage_GetWidth(page, &fWidth);
FSDK_PDFPage_GetHeight(page, &fHeight);
int width= (int)fWidth;
int height= (int)fWidth;
java
import static com.foxit.sdk.pdf.PDFPage.*;
...

// Assuming PDFPage page has been loaded and parsed.
...
int width = (int) page.getWidth();
int height = (int) page.getHeight();
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    #replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
...
# Assuming PDFPage page has been loaded and parsed.
width = int(page.GetWidth())
height = int(page.GetHeight())
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFPage page has been loaded and parsed.
...
float width = [page getWidth];
float height = [page getHeight];
...
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

...
// Assuming PDFPage page has been loaded and parsed.
let width = page.GetWidth();
let height = page.GetHeight();
csharp
using foxit.pdf;
using foxit.common;
...

// Assuming PDFPage page has been loaded and parsed.
...
int width = (int)(page.GetWidth());
int height = (int)(page.GetHeight());
...

Calculate the Bounding Box of Page Content

c++
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace common;
using namespace pdf;
...
//Assuming PDFDoc doc has been loaded.
//Assuming PDFPage page has been loaded and parsed.

RectF ret = page.CalcContentBBox(PDFPage::e_CalcContentsBox);
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_pdfpage_c.h"
...
// Assuming FS_PDFDOC_HANDLE doc has been loaded.
// Assuming FS_PDFPAGE_HANDLE page has been loaded and parsed.

FSRectF ret;
ret.left = 0;
ret.bottom = 0;
ret.top = 0;
ret.right = 0;
FSDK_PDFPage_CalcContentBBox(page, e_FSCalcContentsBox, &ret);
...
java
import static com.foxit.sdk.pdf.PDFPage.*;
...

// Assuming PDFPage page has been loaded and parsed.
...

RectF calcRc = page.calcContentBBox(e_CalcContentsBox);
float fcalcRc = calcRc.width();
float fcalcRcHeight = calcRc.height();
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    #replace with python2 lib path
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Assuming PDFDoc doc has been loaded.
# Assuming PDFPage page has been loaded and parsed.
ret = page.CalcContentBBox(PDFPage.e_CalcContentsBox)
...
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFPage page has been loaded and parsed.
...
FSRectF* content_box = [page calcContentBBox:FSPDFPageCalcContentsBox];
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

...
// Assuming PDFDoc doc has been loaded.
// Assuming PDFPage page has been loaded and parsed.
let ret = page.CalcContentBBox(FSDK.PDFPage.e_CalcContentsBox);
...
csharp
using foxit.pdf;
...

// Assuming PDFPage page has been loaded and parsed.
...

RectF ret = page.CalcContentBBox(PDFPage.CalcMarginMode.e_CalcContentsBox);
...

Create a PDF Page and Set Its Size

c++
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace common;
using namespace pdf;
...
// Assuming PDFDoc doc has been loaded.

PDFPage page = doc.InsertPage(index, PageWidth, PageHeight);
C
#include "include/fs_basictypes_c.h"
#include "include/fs_pdfdoc_c.h"
#include "include/fs_pdfpage_c.h"
...
// Assuming FS_PDFDOC_HANDLE doc has been loaded.

FS_PDFPAGE_HANDLE page;
FSDK_PDFDoc_InsertPage(doc, index, PageWidth, PageHeight, &page);
java
import static com.foxit.sdk.pdf.PDFPage.*;
...

// Assuming PDFDoc doc has been loaded.

// Insert a new blank PDF page to document, which will be inserted to the first page.
PDFPage newBlankPage = doc.insertPage(-1, 500, 800);
			
// Insert a new blank PDF page to document, which will be inserted at index 1.
PDFPage newBlankPage = doc.insertPage(1, 500, 800);
			
// Insert a new blank PDF page to document, which will be inserted to the end.
PDFPage newBlankPage = doc.insertPage(doc.getPageCount(), e_SizeLetter);
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Assuming PDFDoc doc has been loaded.
page = doc.InsertPage(index, PageWidth, PageHeight)
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFDoc doc has been loaded.
...

float w = 612.0;
float h = 792.0;
FSPDFPage* page = [doc insertPage:index width:w height:h];
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");

...
// Assuming PDFDoc doc has been loaded.
let page = doc.InsertPage(index, PageWidth, PageHeight)
csharp
using foxit.pdf;
...

// Assuming PDFDoc doc has been loaded.

PDFPage page = doc.InsertPage(index, PageWidth, PageHeight);

Delete a PDF Page

c++
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace common;
using namespace pdf;
...
// Assuming PDFDoc doc has been loaded.

// Remove a PDF page by page index.
doc.RemovePage(index);

// Remove a specified PDF page.
doc.RemovePage(&page);
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_pdfdoc_c.h"
#include "include/fs_pdfpage_c.h"
...
// Assuming FS_PDFDOC_HANDLE doc has been loaded.

FS_PDFPAGE_HANDLE page;
FSDK_PDFDoc_InsertPage(doc, index, PageWidth, PageHeight, &page);
java
import static com.foxit.sdk.pdf.PDFDoc.*;
...

// Assuming PDFDoc doc has been loaded.

// Remove a PDF page by page index.
doc.removePage(index);

// Remove a specified PDF page.
doc.removePage(page);
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    #replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
...
# Assuming PDFDoc doc has been loaded.

# Remove a PDF page by page index.
doc.RemovePage(index)

# Remove a specified PDF page.
doc.RemovePage(page)
...
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFDoc doc has been loaded.

// Remove a PDF page by page index.
[doc removePage:index];

// Remove a specified PDF page.
[doc removePageWithPDFPage:page];
...
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");
...
// Assuming PDFDoc doc has been loaded.

// Remove a PDF page by page index.
doc.RemovePage(index)

// Remove a specified PDF page.
doc.RemovePage(page)
...
csharp
using foxit.pdf;
...

// Assuming PDFDoc doc has been loaded.

// Remove a PDF page by page index.
doc.RemovePage(index);

// Remove a specified PDF page.
doc.RemovePage(page);
...

Flatten a PDF Page

c++
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace common;
using namespace pdf;
...
// Assuming PDFPage page has been loaded and parsed.

// Flatten all contents of a PDF page.
page.Flatten(true, PDFPage::e_FlattenAll);

// Flatten a PDF page without annotations.
page.Flatten(true, PDFPage::e_FlattenNoAnnot);

// Flatten a PDF page without form controls.
page.Flatten(true, PDFPage::e_FlattenNoFormControl);

// Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
page.Flatten(true, PDFPage::e_FlattenNoAnnot | PDFPage::e_FlattenNoFormControl);
...
C
#include "include/fs_basictypes_c.h"
#include "include/fs_pdfpage_c.h"
...
// Assuming FS_PDFPAGE_HANDLE page has been loaded and parsed.

// Flatten all contents of a PDF page.
FS_BOOL return_Flatten;
FSDK_PDFPage_Flatten(page, true, e_FSFlattenAll, &return_Flatten);

// Flatten a PDF page without annotations.
FSDK_PDFPage_Flatten(page, true, e_FSFlattenNoAnnot, &return_Flatten);

// Flatten a PDF page without form controls.
FSDK_PDFPage_Flatten(page, true, e_FSFlattenNoFormControl, &return_Flatten);

// Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
FSDK_PDFPage_Flatten(page, true, e_FSFlattenNoAnnot | e_FSFlattenNoFormControl, &return_Flatten);
...
java
import static com.foxit.sdk.pdf.PDFPage.*;
...

// Assuming PDFPage page has been loaded and parsed.

// Flatten all contents of a PDF page.
page.flatten(true, e_FlattenAll);

// Flatten a PDF page without annotations.
page.flatten(true, e_FlattenNoAnnot);

// Flatten a PDF page without form controls.
page.flatten(true, e_FlattenNoFormControl);

// Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
page.flatten(true, e_FlattenNoAnnot | e_FlattenNoFormControl);
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with python2 lib path
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

page = PDFPage()
...
# Assuming PDFPage page has been loaded and parsed.
# Flatten all contents of a PDF page.
page.Flatten(True, PDFPage.e_FlattenAll)

# Flatten a PDF page without annotations.
page.Flatten(True, PDFPage.e_FlattenNoAnnot)

# Flatten a PDF page without form controls.
page.Flatten(True, PDFPage.e_FlattenNoFormControl)

# Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
page.Flatten(True, PDFPage.e_FlattenNoAnnot | PDFPage.e_FlattenNoFormControl)
...
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFPage page has been loaded and parsed.

// Flatten all contents of a PDF page.
[page flatten:YES options:FSPDFPageFlattenAll];

// Flatten a PDF page without annotations. 
[page flatten:YES options:FSPDFPageFlattenNoAnnot];

// Flatten a PDF page without form controls.
[page flatten:YES options:FSPDFPageFlattenNoFormControl];

// Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
[page flatten:YES options:FSPDFPageFlattenNoAnnot|FSPDFPageFlattenNoFormControl];
...
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");
...

let page = new FSDK.PDFPage();
// Assuming PDFPage page has been loaded and parsed.
// Flatten all contents of a PDF page.
page.Flatten(true, FSDK.PDFPage.e_FlattenAll)

// Flatten a PDF page without annotations.
page.Flatten(true, FSDK.PDFPage.e_FlattenNoAnnot)

// Flatten a PDF page without form controls.
page.Flatten(true, FSDK.PDFPage.e_FlattenNoFormControl)

// Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
page.Flatten(true, FSDK.PDFPage.e_FlattenNoAnnot | PDFPage.e_FlattenNoFormControl)
...
csharp
using foxit.pdf;
...

// Assuming PDFPage page has been loaded and parsed.

// Flatten all contents of a PDF page.
page.Flatten(true, (int)PDFPage.FlattenOptions.e_FlattenAll);

// Flatten a PDF page without annotations.
page.Flatten(true, (int)PDFPage.FlattenOptions.e_FlattenNoAnnot);

// Flatten a PDF page without form controls.
page.Flatten(true, (int)PDFPage.FlattenOptions.e_FlattenNoFormControl);

// Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).
page.Flatten(true, (int)(PDFPage.FlattenOptions.e_FlattenNoAnnot | PDFPage.FlattenOptions.e_FlattenNoFormControl));
...

Get and Set Page Thumbnails in a PDF Document

c++
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace common;
using namespace pdf;
...
// Assuming PDFPage page has been loaded and parsed.

Bitmap bmp();
// Write bitmap data to the bmp object.
...
// Set thumbnails to the page.
page.SetThumbnail(bmp);
// Load thumbnails in the page.
Bitmap bitmap = page.LoadThumbnail();
C
#include "include/fs_basictypes_c.h"
#include "include/fs_pdfpage_c.h"
...
// Assuming FS_PDFPAGE_HANDLE page has been loaded and parsed.

FS_BITMAP_HANDLE bmp;
FSDK_Bitmap_Create0(&bmp);
// Write bitmap data to the bmp object.
...
// Set thumbnails to the page.
FSDK_PDFPage_SetThumbnail(page, bmp);
// Load thumbnails in the page.
FS_BITMAP_HANDLE bitmap;
FSDK_PDFPage_LoadThumbnail(page, &bitmap);
...
java
import static com.foxit.sdk.pdf.PDFPage.*;
...

// Assuming PDFPage page has been loaded and parsed.

...
// Load the thumbnail bitmap. If the return value of function db.isEmpty() is true means no thumbnail can be found.
Bitmap db = page.loadThumbnail();
if (!db.isEmpty())
{
    int dbWidth = db.getWidth();
    int dbHeight = db.getHeight();
}
			
// Set page thumbnail, db should be a valid bitmap.
page.setThumbnail(db);
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
...
# Assuming PDFPage page has been loaded and parsed.

bmp = Bitmap()
# Write bitmap data to the bmp object.
...
# Set thumbnails to the page.
page.SetThumbnail(bmp)
# Load thumbnails in the page.
bitmap = page.LoadThumbnail()
...
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFPage page has been loaded and parsed.
FSBitmap* thumbnail_bmp = [page loadThumbnail];
js
const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");
...
// Assuming PDFPage page has been loaded and parsed.

let bitmap = new FSDK.Bitmap();
// Write bitmap data to the bmp object.
...
// Set thumbnails to the page.
page.SetThumbnail(bmp)
// Load thumbnails in the page.
bitmap = page.LoadThumbnail()
...
csharp
using foxit.pdf;
...

// Assuming PDFPage page has been loaded and parsed.

// Get page thumbnails.
page.LoadThumbnail();

// Set thumbnails to the page. 
// Assuming Bitmap bitmap has been created.
page.SetThumbnail(bitmap);
...