How to Render using Foxit PDF SDK (Objective-C)
PDF rendering is realized through the Foxit renderer, a graphics engine that is used to render a page to a bitmap or platform graphics device. Foxit PDF SDK provides APIs to set rendering options/flags. As an example, you can set up a flag to decide whether to render form fields and signature, or whether to draw image anti-aliasing and path anti-aliasing. To render, you can use the following APIs:
- To render page and annotations, first use function FSRenderer::setRenderContentFlags to decide whether to render page and annotation both or not, and then use function FSRenderer::startRender to do the rendering. Function FSRenderer::startQuickRender can also be used to render page but only for thumbnail purpose.
- To render a single annotation, use function FSRenderer::renderAnnot.
- To render on a bitmap, use function FSRenderer::startRenderBitmap.
- To render a reflowed page, use function FSRenderer::startRenderReflowPage.
Widget annotation is always associated with form field and form control in Foxit PDF SDK. For how to render widget annotations, here is a recommended flow:
- After loading a PDF page, first render the page and all annotations in this page (including widget annotations).
- Then, if use FSFiller object to fill the form, the function FSFiller::render should be used to render the focused form control instead of the function FSRenderer::renderAnnot.
Example:
How to render a page to a bitmap
#include "FSPDFObjC.h" ... // Assuming FSPDFPage page has been loaded and parsed. int width = (int)[page getWidth]; int height = (int)[page getHeight]; FSMatrix2D* matrix = [page getDisplayMatrix:0 top:0 width:width height:height rotate:page.rotation]; // Prepare a bitmap for rendering. FSBitmap* bitmap = [[FSBitmap alloc] initWithWidth:width height:height format:FSBitmapDIBArgb buffer:nil pitch:0]; [bitmap fillRect:0xFFFFFFFF rect:nil]; // Render page. FSRenderer* render = [[FSRenderer alloc] initWithBitmap:bitmap is_rgb_order:NO]; [render startRender:page matrix:matrix pause:nil]; ...
How to render page and annotation
#include "FSPDFObj.h" ... // Assuming PDFPage page has been loaded and parsed. int width = (int)[page getWidth]; int height = (int)[page getHeight]; FSMatrix2D* matrix = [page getDisplayMatrix:0 top:0 width:width height:height rotate:page.rotation]; // Prepare a bitmap for rendering. FSBitmap* bitmap = [[FSBitmap alloc] initWithWidth:width height:height format:FSBitmapDIBArgb buffer:nil pitch:0]; [bitmap fillRect:0xFFFFFFFF rect:nil]; // Render page. FSRenderer* render = [[FSRenderer alloc] initWithBitmap:bitmap is_rgb_order:NO]; unsigned int render_flag = FSRendererRenderPage | FSRendererRenderAnnot; [render setRenderContentFlags:render_flag]; [render startRender:page matrix:matrix pause:nil]; ...
Updated on April 9, 2019