How to Render using Foxit PDF SDK (.NET)
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 Renderer.SetRenderContentFlags to decide whether to render page and annotation both or not, and then use function Renderer.StartRender to do the rendering. Function Renderer.StartQuickRender can also be used to render page but only for thumbnail purpose.
- To render a single annotation, use function Renderer.RenderAnnot.
- To render on a bitmap, use function Renderer.StartRenderBitmap.
- To render a reflowed page, use function Renderer.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 pdf.interform.Filler object to fill the form, the function pdf.interform.Filler.Render should be used to render the focused form control instead of the function Renderer.RenderAnnot.
Example:
How to render a page to a bitmap
using foxit; using foxit.common; using foxit.common.fxcrt; using foxit.pdf; // Assuming PDFPage page has been loaded and parsed. int width = (int)(page.GetWidth()); int height = (int)(page.GetHeight()); Matrix2D matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation()); // Prepare a bitmap for rendering. System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics draw = Graphics.FromImage(bitmap); draw.Clear(Color.White); // Render page. Renderer render = new Renderer(bitmap, false); render.StartRender(page, matrix, null); ...
How to render page and annotation
using foxit; using foxit.common; using foxit.common.fxcrt; using foxit.pdf; // Assuming PDFPage page has been loaded and parsed. ... int width = (int)(page.GetWidth()); int height = (int)(page.GetHeight()); Matrix2D matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation()); // Prepare a bitmap for rendering. System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics draw = Graphics.FromImage(bitmap); draw.Clear(Color.White); // Render page Renderer render = new Renderer(bitmap, false); render.SetRenderContentFlags((int)Renderer.ContentFlag.e_RenderAnnot | (int)Renderer.ContentFlag.e_RenderPage); render.StartRender(page, matrix, null); ...
Updated on April 9, 2019