Class: PDFDraw


new 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.


<static> create(dpi)

PdFDraw constructor and destructor

Name Type Description
dpi number

Default resolution used to rasterize pages. If the parameter is not specified, the initial resolution is 92 dots per inch. DPI parameter can be modified at any time using PDFDraw::SetDPI() method.


A promise that resolves to an object of type: "PDFDraw"



Frees the native memory of the object.


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).

Name Type Description
enable_aa boolean

if true anti-aliasing will be enabled.

Default Value:
  • Anti-aliasing is enabled by default.


enables or disables caching. Caching can improve the rendering performance in cases where the same page will be drawn multiple times.

Name Type Description
enabled boolean

if true PDFRasterizer will cache frequently used graphics objects.


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

Name Type Description
rect PDFNet.rect

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


Set the color post processing transformation. This transform is applied to the rasterized bitmap as the final step in the rasterization process, and is applied directly to the resulting bitmap (disregarding any color space information). Color post processing only supported for RGBA output.

Name Type Description
mode number/enum
PDFNet.PDFRasterizer.ColorPostProcessMode = {
	e_postprocess_none : 0
	e_postprocess_invert : 1

is the specific transform to be applied

setDefaultPageColor(r, g, b)

sets the default color of the page backdrop.

Name Type Description
r number

the red component of the page backdrop color.

g number

the green component of the page backdrop color.

b number

the blue component of the page backdrop color.

Default Value:
  • By default, the page color is white.


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.

Name Type Description
dpi number

value to set the image resolution to. Higher value = higher resolution.


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

Name Type Description
render_annots boolean

True to draw annotations, false otherwise.


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

Name Type Description
flip_y boolean

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


Sets the gamma factor used for anti-aliased rendering.

Name Type Description
exp number

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

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).


Enable or disable highlighting form fields. Default is disabled.

Name Type Description
highlight boolean

true to highlight, false otherwise.

setImageSize(width, height, preserve_aspect_ratio)

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.

Name Type Description
width number

The width of the image, in pixels/samples.

height number

The height of the image, in pixels/samples.

preserve_aspect_ratio boolean

True to preserve the aspect ratio, false otherwise. By default, preserve_aspect_ratio is true.

setImageSmoothing(smoothing_enabled, hq_image_resampling)

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.

Name Type Description
smoothing_enabled boolean

True to enable image smoothing, false otherwise.

hq_image_resampling boolean

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

Default Value:
  • image smoothing is enabled and hq_image_resampling is false.


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.

Name Type Description
ctx PDFNet.OCGContext

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


enable or disable support for overprint and overprint simulation. 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).

Name Type Description
op number/enum
PDFNet.PDFRasterizer.OverprintPreviewMode = {
	e_op_off : 0
	e_op_on : 1
	e_op_pdfx_on : 2

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

Default Value:
  • By default overprint is only enabled for PDF/X files.


Selects the page box/region to rasterize.

Name Type Description
region number/enum
PDFNet.Page.Box = {
	e_media : 0
	e_crop : 1
	e_bleed : 2
	e_trim : 3
	e_art : 4

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


sets the page color to transparent.

Name Type Description
is_transparent boolean

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

Default Value:
  • 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.


Enable or disable path hinting.

Name Type Description
enable_hinting boolean

if true path hinting will be enabled. 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.


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.

Name Type Description
is_printing boolean

set to true if the page should be rendered in print mode.

Default Value:
  • By default, print mode flag is set to false.


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.

Name Type Description
type number/enum
PDFNet.PDFRasterizer.Type = {
	e_BuiltIn : 0
	e_GDIPlus : 1

Rasterizer type.


Sets the rotation value for this page.

Name Type Description
angle number/enum
PDFNet.Page.Rotate = {
	e_0 : 0
	e_90 : 1
	e_180 : 2
	e_270 : 3

Rotation value to be set for a given page. Must be one of the Page::Rotate values.

setThinLineAdjustment(grid_fit, stroke_adjust)

Set thin line adjustment parameters.

Name Type Description
grid_fit boolean

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.

stroke_adjust boolean

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.