Foxit PDF SDK for Windows

How to manage your PDF Pages using Foxit PDF SDK (.NET)

In PDF development, a PDF page means much more than in the final user’s PDF editor or viewer. Page objects help group and identify multiple objects in the PDF to perform other operations. A PDFPage object is retrieved from a PDF document by function PDFDoc.getPage. Page level APIs provide functions to parse, render, edit (includes creating, deleting and flattening) a page, retrieve PDF annotations, read and set the properties of a page, and more. For most cases, a PDF page needs to be parsed before it is rendered or processed.

In this article, we will provide sample code examples for handling your pages using Foxit PDF SDK:

Example:

How to get page size

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

How to calculate bounding box of page contents

using foxit.pdf;
...
// Assuming PDFPage page has been loaded and parsed.
...
RectF ret = page.CalcContentBBox(PDFPage.CalcMarginMode.e_CalcContentsBox);
...

How to create a PDF page and set the size

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

How to delete a PDF page

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);
...

How to flatten a PDF page

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));
...

How to get and set page thumbnails in a PDF document

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);
...

Updated on April 3, 2019

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: