Show / Hide Table of Contents

Class PDFDraw

PDFDraw contains methods for converting PDF pages to images and to Bitmap objects. Utility methods are provided to export PDF pages to various raster formats as well as to convert pages to GDI+ bitmaps for further manipulation or drawing.

Inheritance
System.Object
PDFDraw
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: pdftron.PDF
Assembly: PDFNetAndroid.dll
Syntax
public class PDFDraw : IDisposable
Remarks

This class is available on all platforms supported by PDFNet.

Constructors

PDFDraw()

PDFDraw constructor and destructor.

Declaration
public PDFDraw()
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

PDFDraw(Double)

Instantiates a new pDF draw.

Declaration
public PDFDraw(double dpi)
Parameters
Type Name Description
System.Double dpi

the dpi

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Methods

Destroy()

Declaration
public void Destroy()

Dispose()

Declaration
public void Dispose()

Dispose(Boolean)

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing

Export(Page, String)

A utility method to export the given PDF page to an image file.

Declaration
public void Export(Page page, string filename)
Parameters
Type Name Description
Page page

The source PDF page.

System.String filename
  • The name of the output image file. The filename should include the extension suffix (e.g. 'c:/output/myimage.png').
Remarks

By default, the function exports to PNG.. The file format of the output image. Currently supported formats are:

  • "RAW" RAW format. There are four possibilities: e_rgba - if transparent and color page; e_gray_alpha - if transparent and gray page; e_rgb - if opaque and color page; e_gray - if opaque and gray page.
  • "BMP" Bitmap image format (BMP)
  • "JPEG" Joint Photographic Experts Group (JPEG) image format
  • "PNG" 24-bit W3C Portable Network Graphics (PNG) image format
  • "PNG8" 8-bit, palettized PNG format. The exported file size should be smaller than the one generated using "PNG", possibly at the expense of some image quality.
  • "TIFF" Tag Image File Format (TIFF) image format.
  • "TIFF8" Tag Image File Format (TIFF) image format (with 8-bit pallete).

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Export(Page, String, String)

Export.

Declaration
public void Export(Page page, string filename, string format)
Parameters
Type Name Description
Page page

the page

System.String filename

the filename

System.String format

the format

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Export(Page, String, String, Obj)

Export.

Declaration
public void Export(Page page, string filename, string format, Obj encoder_hints)
Parameters
Type Name Description
Page page

the page

System.String filename

the filename

System.String format

the format

Obj encoder_hints

the encoder_params

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Finalize()

Releases all resources used by the PDFDraw

Declaration
protected void Finalize()

GetBitmap(Page)

Declaration
public Bitmap GetBitmap(Page page)
Parameters
Type Name Description
Page page
Returns
Type Description
Android.Graphics.Bitmap

GetBitmap(Page, PDFDraw.PixelFormat, Boolean)

Declaration
public BitmapInfo GetBitmap(Page page, PDFDraw.PixelFormat pix_fmt, bool demult)
Parameters
Type Name Description
Page page
PDFDraw.PixelFormat pix_fmt
System.Boolean demult
Returns
Type Description
BitmapInfo

GetBitmapInfo(Page)

Declaration
public BitmapInfo GetBitmapInfo(Page page)
Parameters
Type Name Description
Page page
Returns
Type Description
BitmapInfo

SetAntiAliasing(Boolean)

Enable or disable anti-aliasing. Anti-Aliasing is a technique used to improve the visual quality of images when displaying them on low resolution devices (for example, low DPI computer monitors). Anti-aliasing is enabled by default.

Declaration
public void SetAntiAliasing(bool enable_aa)
Parameters
Type Name Description
System.Boolean enable_aa

whether to enable anti-aliasing

SetCaching(Boolean)

Sets the caching.

Declaration
public void SetCaching(bool enabled)
Parameters
Type Name Description
System.Boolean enabled

the new caching

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetClipRect(Rect)

Clip the render region to the provided rect (in page space)

Declaration
public void SetClipRect(Rect clip_rect)
Parameters
Type Name Description
Rect clip_rect

Clipping rect. By default, PDFDraw will rasterize the entire page box.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetDefaultPageColor(Byte, Byte, Byte)

Sets the default color of the page backdrop.

Declaration
public void SetDefaultPageColor(byte r, byte g, byte b)
Parameters
Type Name Description
System.Byte r
System.Byte g
System.Byte b

SetDPI(Double)

Sets the output image resolution.

DPI stands for Dots Per Inch. This parameter is used to specify the output image size and quality. A typical screen resolution for monitors these days is 92 DPI, but printers could use 200 DPI or more.

Declaration
public void SetDPI(double dpi)
Parameters
Type Name Description
System.Double dpi

the new dPI

Remarks

The size of resulting image is a function of DPI and the dimensions of the source PDF page. For example, is DPI is 92 and page is 8 inches wide, the output bitmap will have 92*8 = 736 pixels per line. If you know the dimensions of the destination bitmap, but don't care about DPI of the image you can use pdfdraw.SetImageSize() instead.

if you would like to rasterize extremely large bitmaps (e.g. with resolutions of 2000 DPI or more) it is not practical to use PDFDraw directly because of the memory required to store the entire image. In this case, you can use PDFRasterizer directly to generate the rasterized image in stripes or tiles.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetDrawAnnotations(Boolean)

Enable or disable annotation and forms rendering. By default, all annotations and form fields are rendered.

Declaration
public void SetDrawAnnotations(bool render_annots)
Parameters
Type Name Description
System.Boolean render_annots

True to draw annotations, false otherwise.

SetFlipYAxis(Boolean)

Flips the vertical (i.e. Y) axis of the image.

Declaration
public void SetFlipYAxis(bool flip_y)
Parameters
Type Name Description
System.Boolean flip_y

true to flip the Y axis, false otherwise. For compatibility with most raster formats 'flip_y' is true by default.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetGamma(Double)

Sets the gamma factor used for anti-aliased rendering.

Declaration
public void SetGamma(double exp)
Parameters
Type Name Description
System.Double exp

exponent value of gamma function. Typical values are in the range from 0.1 to 3.

Remarks

Gamma correction can be used to improve the quality of anti-aliased image output and can (to some extent) decrease the appearance common anti-aliasing artifacts (such as pixel width lines between polygons). Gamma correction is used only in the built-in rasterizer.

SetHighlightFields(Boolean)

Enable or disable highlighting form fields. Default is disabled.

Declaration
public void SetHighlightFields(bool highlight_fields)
Parameters
Type Name Description
System.Boolean highlight_fields

true to highlight, false otherwise.

SetImageSize(Int32, Int32)

SetImageSize can be used instead of SetDPI() to adjust page scaling so that image fits into a buffer of given dimensions.

If this function is used, DPI will be calculated dynamically for each page so that every page fits into the buffer of given dimensions.

Declaration
public void SetImageSize(int width, int height)
Parameters
Type Name Description
System.Int32 width
  • The width of the image, in pixels/samples.
System.Int32 height
  • The height of the image, in pixels/samples.
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetImageSize(Int32, Int32, Boolean)

Sets the image size.

Declaration
public void SetImageSize(int width, int height, bool preserve_aspect_ratio)
Parameters
Type Name Description
System.Int32 width

the width

System.Int32 height

the height

System.Boolean preserve_aspect_ratio

the preserve_aspect_ratio

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetImageSmoothing(Boolean, Boolean)

Enable or disable image smoothing.
The rasterizer allows a tradeoff between rendering quality and rendering speed. This function can be used to indicate the preference between rendering speed and quality. image smoothing is enabled by default.

Declaration
public void SetImageSmoothing(bool smoothing_enabled, bool hq_image_resampling)
Parameters
Type Name Description
System.Boolean smoothing_enabled

whether to enable image smoothing

System.Boolean hq_image_resampling

whether to use a higher quality (but slower) smoothing algorithm

Remarks

image smoothing option has effect only if the source image has higher resolution that the output resolution of the image on the rasterized page. PDFNet automatically controls at what resolution/zoom factor, 'image smoothing' needs to take effect.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetOCGContext(Context)

Sets the Optional Content Group (OCG) context that should be used when rendering the page. This function can be used to selectively render optional content (such as PDF layers) based on the states of optional content groups in the given context.

Declaration
public void SetOCGContext(Context ctx)
Parameters
Type Name Description
Context ctx

Optional Content Group (OCG) context, or NULL if the rasterizer should render all content on the page.

SetOverprint(PDFRasterizer.OverprintPreviewMode)

Enable or disable support for overprint. Overprint is a device dependent feature and the results will vary depending on the output color space and supported colorants (i.e. CMYK, CMYK+spot, RGB, etc). By default overprint is enabled for only PDF/X files.

Declaration
public void SetOverprint(PDFRasterizer.OverprintPreviewMode op)
Parameters
Type Name Description
PDFRasterizer.OverprintPreviewMode op

e_op_on: always enabled; e_op_off: always disabled; e_op_pdfx_on: enabled for PDF/X files only.

SetPageBox(Page.Box)

Selects the page box/region to rasterize.

Declaration
public void SetPageBox(Page.Box region)
Parameters
Type Name Description
Page.Box region

Page box to rasterize. By default, PDFDraw will rasterize page crop box.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetPageTransparent(Boolean)

Sets the page color to transparent. By default, PDFDraw assumes that the page is imposed directly on an opaque white surface. Some applications may need to impose the page on a different backdrop. In this case any pixels that are not covered during rendering will be transparent.

Declaration
public void SetPageTransparent(bool is_transp)
Parameters
Type Name Description
System.Boolean is_transp

If true, page's backdrop color will be transparent. If false, the page's backdrop will be a opaque white.

Remarks

If true, page's backdrop color will be transparent. If false, the page's backdrop will be a opaque white.

SetPathHinting(Boolean)

Enable or disable path hinting. Path hinting is used to slightly adjust paths in order to avoid or alleviate artifacts of hair line cracks between certain graphical elements. This option is turned on by default.

Declaration
public void SetPathHinting(bool enable_ph)
Parameters
Type Name Description
System.Boolean enable_ph

whether to enable path hinting.

SetPrintMode(Boolean)

Tells the rasterizer to render the page 'print' mode. Certain page elements (such as annotations or OCG-s) are meant to be visible either on the screen or on the printed paper but not both. A common example, is the "Submit" button on electronic forms.

Declaration
public void SetPrintMode(bool is_printing)
Parameters
Type Name Description
System.Boolean is_printing

set to true if the page should be rendered in print mode. By default, print mode flag is set to false.

SetRasterizerType(PDFRasterizer.Type)

Sets the core graphics library used for rasterization and rendering. Using this method it is possible to quickly switch between different implementations. By default, PDFDraw uses the built-in, platform independent rasterizer.

Declaration
[Obsolete("Deprecated, will be removed in the next update.")]
public void SetRasterizerType(PDFRasterizer.Type type)
Parameters
Type Name Description
PDFRasterizer.Type type

Rasterizer type.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetRotate(Page.Rotate)

Sets the rotation value for this page.

Declaration
public void SetRotate(Page.Rotate r)
Parameters
Type Name Description
Page.Rotate r

the new rotate

Remarks

This method is used only for drawing purposes and it does not modify the document (unlike Page.SetRotate()).

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetThinLineAdjustment(Boolean, Boolean)

Set thin line adjustment parameters.

Declaration
public void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust)
Parameters
Type Name Description
System.Boolean pixel_grid_fit

if true (horizontal/vertical) thin lines will be snapped to integer pixel positions. This helps make thin lines look sharper and clearer. This option is turned off by default and it only works if path hinting is enabled.

System.Boolean stroke_adjust

if true auto stroke adjustment is enabled. Currently, this would make lines with sub-pixel width to be one-pixel wide. This option is turned on by default.

Implements

System.IDisposable
In This Article
Back to top Generated by DocFX