How to manage your PDF Pages using Foxit PDF SDK (Objective-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:
Contents
How to get page size
#include "FSPDFObjC.h" ... // Assuming FSPDFPage page has been loaded and parsed. ... float width = [page getWidth]; float height = [page getHeight]; ...
How to calculate bounding box of page contents
#include "FSPDFObjC.h" ... // Assuming FSPDFPage page has been loaded and parsed. ... FSRectF* content_box = [page calcContentBBox:FSPDFPageCalcContentsBox];
How to create a PDF page and set the size
#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];
How to delete a PDF page
#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]; ...
How to flatten a PDF page
#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]; ...
How to get and set page thumbnails in a PDF document
#include "FSPDFObjC.h" ... // Assuming FSPDFPage page has been loaded and parsed. FSBitmap* thumbnail_bmp = [page loadThumbnail];
Updated on April 3, 2019