Class: PDFDraw

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

Extends

Members


<static> PixelFormat

Properties:
Name Type Description
e_rgba number
e_bgra number
e_rgb number
e_bgr number
e_gray number
e_gray_alpha number
e_cmyk number

Methods


<static> create( [dpi])

PdFDraw constructor and destructor
Parameters:
Name Type Argument Description
dpi number <optional>
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.
Returns:
A promise that resolves to an object of type: "PDFNet.PDFDraw"
Type
Promise.<PDFNet.PDFDraw>

<static> exportBuffer(page [, format] [, encoder_params])

Export the given PDF page to a buffer.
Parameters:
Name Type Argument Description
page PDFNet.Page The source PDF page.
format string <optional>
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. NOTE that if page is set to be transparent (SetPageTransparent), the output color channels are already multiplied by the alpha channel. - "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 palete). By default, the function exports to PNG.
encoder_params PDFNet.Obj <optional>
An optional SDF dictionary object containing key/value pairs representing optional encoder parameters. The following table list possible parameters for corresponding export filters:
Parameter/Key Output Format Description/Value Example
Quality JPEG The value for compression 'Quality' must be a number between 0 and 100 specifying the tradeoff between compression ratio and loss in image quality. 100 stands for best quality.

hint.PutNumber("Quality", 60);

See the Example 2 in PDFDraw sample project.

Dither PNG, PNG8, TIFF or TIFF8. A boolean used to enable or disable dithering. Relevent only for when the image is exported in palettized or monochrome mode. hint.PutBool("Dither", true);
ColorSpace PNG or TIFF for grayscale; TIFF for CMYK; PNG, BMP, JPEG, or TIFF for Separation. A name object used to select the rendering and export color space. Currently supported values are "Gray", "RGB, "CMYK", and "Separation". The output image format must support specified color space, otherwise the parameter will be ignored. An example of image format that supports CMYK is TIFF. Image formats that support grayscale are PNG and TIFF. Separation output is supported in either a single N-Channel TIFF, or in separate single-channel files (either PNG, BMP, or JPEG). Output in "Separation" space implies that overprint simulation is on. By default, the image is rendered and exported in RGB color space. hint.PutName("ColorSpace", "CMYK");
BPC PNG or TIFF. A number used to specify 'bits per pixel' in the output file. Currently supported values are 1 and 8 (default is 8). To export monochrome (1 bit per pixel) image, use 1 as the value of BPC parameter and use TIFF or PNG as the export format for the image. By default, the image is not dithered when BPC is 1. To enable dithering add 'Dither' option in the export hint. hint.PutNumber("BPC", 1);
Returns:
A promise that resolves to a Uint8Array containing the page data.
Type
Promise.<Uint8Array>

destroy()

Destructor
Inherited From:
Returns:
Type
Promise.<void>

setAntiAliasing(enable_aa)

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).
Parameters:
Name Type Description
enable_aa boolean if true anti-aliasing will be enabled.
Default Value:
  • Anti-aliasing is enabled by default.
Returns:
Type
Promise.<void>

setCaching( [enabled])

enables or disables caching. Caching can improve the rendering performance in cases where the same page will be drawn multiple times.
Parameters:
Name Type Argument Description
enabled boolean <optional>
if true PDFRasterizer will cache frequently used graphics objects.
Returns:
Type
Promise.<void>

setClipRect(rect)

clip the render region to the provided rect (in page space)
Parameters:
Name Type Description
rect PDFNet.Rect clipping rect. By default, PDFDraw will rasterize the entire page box.
Returns:
Type
Promise.<void>

setColorPostProcessMode(mode)

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.
Parameters:
Name Type Description
mode number
PDFNet.PDFRasterizer.ColorPostProcessMode = {
	e_postprocess_none : 0
	e_postprocess_invert : 1
}
is the specific transform to be applied
Returns:
Type
Promise.<void>

setDefaultPageColor(r, g, b)

sets the default color of the page backdrop.
Parameters:
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.
Returns:
Type
Promise.<void>

setDPI(dpi)

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.
Parameters:
Name Type Description
dpi number value to set the image resolution to. Higher value = higher resolution.
Returns:
Type
Promise.<void>

setDrawAnnotations(render_annots)

Enable or disable annotation and forms rendering. By default, all annotations and form fields are rendered.
Parameters:
Name Type Description
render_annots boolean True to draw annotations, false otherwise.
Returns:
Type
Promise.<void>

setFlipYAxis(flip_y)

Flips the vertical (i.e. Y) axis of the image.
Parameters:
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.
Returns:
Type
Promise.<void>

setGamma(exp)

Sets the gamma factor used for anti-aliased rendering.
Parameters:
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).
Returns:
Type
Promise.<void>

setHighlightFields(highlight)

Enable or disable highlighting form fields. Default is disabled.
Parameters:
Name Type Description
highlight boolean true to highlight, false otherwise.
Returns:
Type
Promise.<void>

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.
Parameters:
Name Type Argument 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 <optional>
True to preserve the aspect ratio, false otherwise. By default, preserve_aspect_ratio is true.
Returns:
Type
Promise.<void>

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.
Parameters:
Name Type Argument Description
smoothing_enabled boolean <optional>
True to enable image smoothing, false otherwise.
hq_image_resampling boolean <optional>
True to use a higher quality (but slower) smoothing algorithm
Default Value:
  • image smoothing is enabled and hq_image_resampling is false.
Returns:
Type
Promise.<void>

setOCGContext(ctx)

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.
Parameters:
Name Type Description
ctx PDFNet.OCGContext Optional Content Group (OCG) context, or NULL if the rasterizer should render all content on the page.
Returns:
Type
Promise.<void>

setOverprint(op)

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).
Parameters:
Name Type Description
op number
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.
Returns:
Type
Promise.<void>

setPageBox(region)

Selects the page box/region to rasterize.
Parameters:
Name Type Description
region number
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.
Returns:
Type
Promise.<void>

setPageTransparent(is_transparent)

sets the page color to transparent.
Parameters:
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.
Returns:
Type
Promise.<void>

setPathHinting(enable_hinting)

Enable or disable path hinting.
Parameters:
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.
Returns:
Type
Promise.<void>

setPrintMode(is_printing)

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.
Parameters:
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.
Returns:
Type
Promise.<void>

setRasterizerType(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.
Parameters:
Name Type Description
type number
PDFNet.PDFRasterizer.Type = {
	e_BuiltIn : 0
	e_GDIPlus : 1
}
Rasterizer type.
Returns:
Type
Promise.<void>

setRotate(angle)

Sets the rotation value for this page.
Parameters:
Name Type Description
angle number
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.
Returns:
Type
Promise.<void>

setThinLineAdjustment(grid_fit, stroke_adjust)

Set thin line adjustment parameters.
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.
Returns:
Type
Promise.<void>

takeOwnership()

Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
Inherited From:
Returns:
Type
void