XFINIUM.PDF 6.9 brings support for selective PDF page content rendering. This means that you can render only the page text or only the vector graphics if you want.
The properties for specifying what content gets rendered are part of PdfRendererSettings
class.
RenderText
– enables or disables the rendering of text content
RenderImages
– enables or disables the rendering of images on the page
RenderGraphics
– enables or disables the rendering of vector graphics
RenderAnnotations
– enables or disables the rendering of page annotations
RenderFormFields
– enables or disables the rendering of form fields
By default all these properties are true so all page content is rendered.
The code below shows how to render only the page content and exclude the annotations and form fields.
C#:
PdfFixedDocument doc = new PdfFixedDocument("sample.pdf"); PdfRendererSettings settings = new PdfRendererSettings(96, 96); // Enable/disable the content to be rendered. settings.RenderText = true; settings.RenderImages = true; settings.RenderGraphics = true; settings.RenderAnnotations = false; settings.RenderFormFields = false; // Render the page without annotations and form fields PdfPageRenderer renderer = new PdfPageRenderer(doc.Pages[0]); FileStream stm = File.OpenWrite("sample.tif"); renderer.ConvertPageToImage(stm, PdfPageImageFormat.Tiff, settings); stm.Flush(); stm.Close();
VB.NET:
Dim doc As New PdfFixedDocument("sample.pdf") Dim settings As New PdfRendererSettings(96, 96) ' Enable/disable the content to be rendered. settings.RenderText = True settings.RenderImages = True settings.RenderGraphics = True settings.RenderAnnotations = False settings.RenderFormFields = False ' Render the page without annotations and form fields Dim renderer As New PdfPageRenderer(doc.Pages(0)) Dim stm As FileStream = File.OpenWrite("sample.tif") renderer.ConvertPageToImage(stm, PdfPageImageFormat.Tiff, settings) stm.Flush() stm.Close()
Download the latest version and give it a try and let us know what you think.
Could you add more fine grained support on what’s rendered?
I’d like to handle ink annotations myself but I can’t find a way to disable their rendering without disabling the rendering of annotations as a whole.
Related to this, is there any way to clone a page?
Well consider your suggestion for implementation, to specify what types of annotations are rendered.
Regarding page cloning, can you give us more details about you try to accomplish?
Well, as a workaround I thought about making a copy of the page and removing the ink annotations before rendering (kind of a dirty way so I’ll probably try something else). However, I couldn’t find a way to make a deep copy of the page so I could modify it without modifying the original page.
You can simply remove the annotation. The actual document is not affected unless you save the document you have in memory. You can also remove the annotation but keep a reference to it and add it back when you finished the job.