Foxit PDF SDK for Windows

How to manage your PDF Pages using Foxit PDF SDK (C++)

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

#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(page.GetWidth());
int height = static_cast(page.GetHeight());

How to calculate bounding box of page contents

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

How to create a PDF page and set the size

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

How to delete a PDF page

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

How to flatten a PDF page

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

How to get and set page thumbnails in a PDF document

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

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: