public class

PDFDraw

extends Object
implements __Delete
java.lang.Object
   ↳ com.pdftron.pdf.PDFDraw

Class Overview

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.

Note: This class is available on all platforms supported by PDFNet.

Summary

Nested Classes
class PDFDraw.IntBufferData  
Constants
int e_bgr The Constant e_bgr.
int e_bgra The Constant e_bgra.
int e_gray The Constant e_gray.
int e_gray_alpha The Constant e_gray_alpha.
int e_postprocess_invert The Constant e_postprocess_invert.
int e_postprocess_none The Constant e_postprocess_none.
int e_rgb The Constant e_rgb.
int e_rgba The Constant e_rgba.
Public Constructors
PDFDraw()
PDFDraw constructor and destructor.
PDFDraw(double dpi)
Instantiates a new PDFDraw with specified DPI(Dots per Inch).
Public Methods
void destroy()
Frees the native memory of the object.
void drawInRect(Graphics g, Page page, int x, int y, int width, int height)
Draws the contents of the page to a given Graphics object.
void export(Page page, String filename)
A utility method to export the given PDF page to a PNG image file.
void export(Page page, String filename, String format, Obj encoder_params)
Export.
void export(Page page, String filename, String format)
Export.
Bitmap getBitmap(Page page, Bitmap image)
Get the bitmap for the given page.
Bitmap getBitmap(Page page)
Get the bitmap from given page
byte[] getByteBuffer(Page page)
PDFDraw.IntBufferData getIntBuffer(Page page)
Get the rendered page with its pixels in an int array.
void setAntiAliasing(boolean enable_aa)
Enable or disable anti-aliasing.
void setCaching(boolean enabled)
Set the caching.
void setCaching()
Enables or disables caching.
void setClipRect(Rect rect)
clip the render region to the provided rect (in page space)
void setColorPostProcessMode(int mode)
Set the color post processing transformation.
void setDPI(double dpi)
Set the output image resolution.
void setDefaultPageColor(byte r, byte g, byte b)
Sets the default color of the page backdrop.
void setDrawAnnotations(boolean render_annots)
Enable or disable annotation and forms rendering.
void setErrorReportProc(ErrorReportProc error_proc, Object data)
Set the error handling function to be called in case an error is encountered during page rendering.
void setFlipYAxis(boolean flip_y)
Flips the vertical (i.e.
void setGamma(double exp)
Set the gamma factor used for anti-aliased rendering.
void setHighlightFields(boolean highlight_fields)
Enable or disable highlighting form fields.
void setImageSize(int width, int height)
SetImageSize can be used instead of SetDPI() to adjust page scaling so that image fits into a buffer of given dimensions.
void setImageSize(int width, int height, boolean preserve_aspect_ratio)
Set the image size.
void setImageSmoothing(boolean smoothing_enabled)
Set the image smoothing.
void setImageSmoothing()
Enable image smoothing.
void setImageSmoothing(boolean smoothing_enabled, boolean hq_image_resampling)
Set the image smoothing.
void setOCGContext(Context ctx)
Set the Optional Content Group (OCG) context that should be used when rendering the page.
void setOverprint(int op)
Enable or disable support for overprint.
void setPageBox(int region)
Selects the page box/region to rasterize.
void setPageTransparent(boolean is_transparent)
Set the page color to transparent.
void setPathHinting(boolean enable_ph)
Enable or disable path hinting.
void setPrintMode(boolean is_printing)
Tells the rasterizer to render the page 'print' mode.
void setRasterizerType(int type)
Set the core graphics library used for rasterization and rendering.
void setRotate(int r)
Set the rotation value for this page.
void setThinLineAdjustment(boolean pixel_grid_fit, boolean stroke_adjust)
Set thin line adjustment parameters.
Protected Methods
void clearList()
Clear list.
void finalize()
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.pdftron.pdf.__Delete

Constants

public static final int e_bgr

The Constant e_bgr.

Constant Value: 3 (0x00000003)

public static final int e_bgra

The Constant e_bgra.

Constant Value: 1 (0x00000001)

public static final int e_gray

The Constant e_gray.

Constant Value: 4 (0x00000004)

public static final int e_gray_alpha

The Constant e_gray_alpha.

Constant Value: 5 (0x00000005)

public static final int e_postprocess_invert

The Constant e_postprocess_invert.

Constant Value: 1 (0x00000001)

public static final int e_postprocess_none

The Constant e_postprocess_none.

Constant Value: 0 (0x00000000)

public static final int e_rgb

The Constant e_rgb.

Constant Value: 2 (0x00000002)

public static final int e_rgba

The Constant e_rgba.

Constant Value: 0 (0x00000000)

Public Constructors

public PDFDraw ()

PDFDraw constructor and destructor.

public PDFDraw (double dpi)

Instantiates a new PDFDraw with specified DPI(Dots per Inch).

Parameters
dpi the input DPI

Public Methods

public void destroy ()

Frees the native memory of the object. This can be explicitly called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public void drawInRect (Graphics g, Page page, int x, int y, int width, int height)

Draws the contents of the page to a given Graphics object.

Parameters
g Java GraphicsBase object
page The source PDF page.
x the x
y the y
width the width
height the height

public void export (Page page, String filename)

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

Parameters
page The source PDF page.
filename The name of the output image file. The filename should include the extension suffix (e.g. 'c:/output/myimage.png').

public void export (Page page, String filename, String format, Obj encoder_params)

Export.

Parameters
page The source PDF page.
filename The name of the output image file. The filename should include the extension suffix (e.g. 'c:/output/myimage.png').
format The file format of the output image. Currently supported formats are: - "RAW" : RAW format, raw BGRA data. - "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). - "GIF" : Graphics Interchange Format (GIF). (PDFNet V4.5 and up) Use PNG8 instead. - "JP2" : (PDFNet V4.5 and up) JPEG2000.
encoder_params a SDF dictionary object containing key/value pairs representing optional encoder parameters.

public void export (Page page, String filename, String format)

Export.

Parameters
page The source PDF page.
filename The name of the output image file. The filename should include the extension suffix (e.g. 'c:/output/myimage.png').
format The file format of the output image. Currently supported formats are: - "RAW" : RAW format, raw BGRA data. - "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). - "GIF" : Graphics Interchange Format (GIF). (PDFNet V4.5 and up) Use PNG8 instead. - "JP2" : (PDFNet V4.5 and up) JPEG2000.

public Bitmap getBitmap (Page page, Bitmap image)

Get the bitmap for the given page.

Parameters
page The source PDF page.
image The input image
Returns
  • the bitmap containing the rasterized image of the given page.

public Bitmap getBitmap (Page page)

Get the bitmap from given page

Parameters
page the input page
Returns
  • the bitmap

public byte[] getByteBuffer (Page page)

public PDFDraw.IntBufferData getIntBuffer (Page page)

Get the rendered page with its pixels in an int array.

Parameters
page the input page
Returns
  • the IntBufferData variable that contains the information of the rendered page.

public void setAntiAliasing (boolean 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). Anti-aliasing is enabled by default.

Parameters
enable_aa whether to enable or disable anti-aliasing

public void setCaching (boolean enabled)

Set the caching.

Parameters
enabled whether to enable caching

public void setCaching ()

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

public void setClipRect (Rect rect)

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

public void setColorPostProcessMode (int 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
mode is the specific transform to be applied

public void setDPI (double dpi)

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

Note: 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.

Note: 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.

Parameters
dpi the new DPI

public void setDefaultPageColor (byte r, byte g, byte b)

Sets the default color of the page backdrop. By default, the page color is white.

Note: If the page backdrop is set to transparent, the page backdrop will be ignored.

Parameters
r the red component of the page backdrop color.
g the green component of the page backdrop color.
b the blue component of the page backdrop color.

public void setDrawAnnotations (boolean render_annots)

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

Parameters
render_annots True to draw annotations, false otherwise.

public void setErrorReportProc (ErrorReportProc error_proc, Object data)

Set the error handling function to be called in case an error is encountered during page rendering.

Parameters
error_proc Error handling callback function (or delegate in .NET)
data Custom data to be passed as a second parameter to 'error_proc'.

public void setFlipYAxis (boolean flip_y)

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

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

public void setGamma (double exp)

Set the gamma factor used for anti-aliased rendering.

Note: Gamma correction is used only in the built-in rasterizer.

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

public void setHighlightFields (boolean highlight_fields)

Enable or disable highlighting form fields. Default is disabled.

Parameters
highlight_fields true to highlight, false otherwise.

public void setImageSize (int width, int height)

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
width - The width of the image, in pixels/samples.
height - The height of the image, in pixels/samples.

public void setImageSize (int width, int height, boolean preserve_aspect_ratio)

Set the image size.

Parameters
width image width
height image height
preserve_aspect_ratio whether to preserve aspect ratio

public void setImageSmoothing (boolean smoothing_enabled)

Set the image smoothing.

Parameters
smoothing_enabled whether to enable image smoothing

public void setImageSmoothing ()

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

Note: 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.

public void setImageSmoothing (boolean smoothing_enabled, boolean hq_image_resampling)

Set the image smoothing.

Parameters
smoothing_enabled whether to enable image smoothing
hq_image_resampling whether to use a higher quality (but slower) smoothing algorithm

public void setOCGContext (Context ctx)

Set 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
ctx Optional Content Group (OCG) context, or NULL if the rasterizer should render all content on the page.

public void setOverprint (int op)

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.

Parameters
op 0: always disabled; 1: always enabled; 2: enabled for PDF/X files only. The default is 2.

public void setPageBox (int region)

Selects the page box/region to rasterize.

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

public void setPageTransparent (boolean is_transparent)

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

Note: If page transparency is enabled, the alpha channel will be preserved when the image is exported as PNG, TIFF, or RAW.

Parameters
is_transparent Set to true if the page's backdrop color is transparent; If is_transparent is set to false the page's backdrop will be a opaque white surface.

public void setPathHinting (boolean enable_ph)

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. Path hinting is enabled by default.

Parameters
enable_ph whether to enable or disable path hinting

public void setPrintMode (boolean 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. By default, print mode flag is set to false.

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

public void setRasterizerType (int type)

Set 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
type Rasterizer type.

public void setRotate (int r)

Set the rotation value for this page.

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

Parameters
r the new rotation value

public void setThinLineAdjustment (boolean pixel_grid_fit, boolean stroke_adjust)

Set thin line adjustment parameters.

Parameters
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 only works if path hinting is enabled.
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.

Protected Methods

protected void clearList ()

Clear list.

protected void finalize ()

Throws
Throwable