Summary: Constants | Ctors | Methods | Inherited Methods | [Expand All]
public class

# PDFRasterizer

extends Object
implements AutoCloseable

java.lang.Object
↳ | com.pdftron.pdf.PDFRasterizer

## Class Overview

PDFRasterizer is a low-level PDF rasterizer. The main purpose of this class is to convert PDF pages to raster images (or bitmaps).

* Note: PDFRasterizer is a relatively low-level class. If you need to convert PDF page to an image format or a Bitmap, consider using PDF::PDFDraw. Similarly, if you are building an interactive PDF viewing application you may want to use PDF::PDFViewCtrl instead.

## Summary

Constants
int | e_postprocess_gradient_map | The Constant e_postprocess_gradient_map.
int | e_postprocess_invert | The Constant e_postprocess_invert.
int | e_postprocess_night_mode | The Constant e_postprocess_night_mode.
int | e_postprocess_none | The Constant e_postprocess_none.

Public Constructors
| PDFRasterizer()

Public Methods
void | close() Frees the native memory of the object.
void | destroy() Frees the native memory of the object.
int | getColorPostProcessMode()
byte[] | rasterize(Page page, int width, int height, int stride, int num_comps, boolean demult, Matrix2D device_mtx, Rect clip) Rasterize a page into a buffer (byte array).
void | rasterize(Page page, int[] buffer, int width, int height, boolean demult, Matrix2D device_mtx, Rect clip) Rasterize a page into a buffer provided by the user.
Separation[] | rasterizeSeparations(Page page, int width, int height, Matrix2D device_mtx, Rect clip, boolean cancel) Rasterize a page into a Separation array.
void | setAntiAliasing(boolean enable_aa) Enable or disable anti-aliasing.
void | setCaching() Enables or disables caching.
void | setCaching(boolean enabled) Set the caching.
void | setCancel(boolean cancel) Signals the rendering thread whether to stop or not.
void | setColorPostProcessColors(int white_color, int black_color) Set the color post processing transformation.
void | setColorPostProcessMapFile(Filter image_file_contents) Set the color post processing transformation.
void | setColorPostProcessMode(int mode) Set the color post processing transformation.
void | setDrawAnnotations(boolean render_annots) Enable or disable annotation and forms rendering.
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 | setImageSmoothing() Enable image smoothing.
void | setImageSmoothing(boolean smoothing_enabled, boolean hq_image_resampling) Set the image smoothing.
void | setImageSmoothing(boolean smoothing_enabled) 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 | setPathHinting(boolean enable_ph) Enable or disable path hinting.
void | setPrintMode(boolean is_printing) Tells the rasterizer to render the page 'print' mode.
void | setThinLineAdjustment(boolean pixel_grid_fit, boolean stroke_adjust) Set thin line adjustment parameters.

[Expand] Inherited Methods
From class java.lang.Object
boolean | equals(Object arg0)
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()
From interface java.lang.AutoCloseable
abstract void | close()

## Constants

#### public static final int e_postprocess_gradient_map

The Constant e_postprocess_gradient_map.

Constant Value: 2 (0x00000002)

#### public static final int e_postprocess_invert

The Constant e_postprocess_invert.

Constant Value: 1 (0x00000001)

#### public static final int e_postprocess_night_mode

The Constant e_postprocess_night_mode.

Constant Value: 3 (0x00000003)

#### public static final int e_postprocess_none

The Constant e_postprocess_none.

Constant Value: 0 (0x00000000)

## Public Constructors

#### public PDFRasterizer ()

##### Throws

PDFNetException |

## Public Methods

#### public void close ()

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

##### Throws

PDFNetException |

#### public void destroy ()

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

##### Throws

PDFNetException |

#### public int getColorPostProcessMode ()

##### Returns

- the current color post processing mode.

#### public byte[] rasterize (Page page, int width, int height, int stride, int num_comps, boolean demult, Matrix2D device_mtx, Rect clip)

Rasterize a page into a buffer (byte array).

##### Parameters

page | The page to rasterize.
width | The width of the target image in pixels.
height | The height of the target image in pixels (the number of rows).
stride | Stride determines the physical width (in bytes) of one row in memory. If this value is negative the direction of the Y axis is inverted. The absolute value of stride is of importance, because it allows rendering in buffers where rows are padded in memory (e.g. in Windows bitmaps are padded on 4 byte boundaries). Besides allowing rendering on the whole buffer stride parameter can be used for rendering in a rectangular subset of a buffer.
num_comps | The number (4 or 5) representing the number of color components in the device color space. For BGR+Alpha set this parameter to 4, and for CMYK+Alpha use 5. If other values are set, exceptions will be thrown.
demult | Specifies if the alpha is de-multiplied from the resulting color components.
device_mtx | Device transformation matrix that maps PDF page from PDF user space into device coordinate space (e.g. pixel space). PDF user space is represented in page units, where one unit corresponds to 1/72 of an inch.
clip | Optional parameter defining the clip region for the page. If the parameter is null or is not specified, PDFRasterizer uses page's crop box as a default clip region.

##### Returns

- A buffer containing the rasterized image (in byte array).

##### Throws

PDFNetException |

#### public void rasterize (Page page, int[] buffer, int width, int height, boolean demult, Matrix2D device_mtx, Rect clip)

Rasterize a page into a buffer provided by the user.

##### Parameters

page | The page to rasterize.
buffer | The buffer into which the page will be rasterized. It has to be pre-allocated by the user and its length should be 'width*height'. It is an int array and each element stores a pixel in ARGB format.
width | The width of the buffer.
height | The height of the buffer.
demult | The RGB components in each pixel are pre-multiplied by its alpha component. Users can set this flag to false to disable such a behavior.
device_mtx | This matrix transforms page contents in PDF space into UI space.
clip | Specifies a rectangular region only within which page contents will be rendered. Note that clip is specified in PDF page space.

##### Throws

PDFNetException |

#### public Separation[] rasterizeSeparations (Page page, int width, int height, Matrix2D device_mtx, Rect clip, boolean cancel)

Rasterize a page into a Separation array.

##### Parameters

page | The page to rasterize.
width | The width of the buffer.
height | The height of the buffer.
device_mtx | This matrix transforms page contents in PDF space into UI space.
clip | Specifies a rectangular region only within which page contents will be rendered. Note that clip is specified in PDF page space.
cancel | An optional variable that can be used to stop the rendering thread.

##### Returns

- A Separation array containing the rasterized image (in byte array).

##### Throws

PDFNetException |

#### 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

##### Throws

PDFNetException |

#### public void setCaching ()

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

##### Throws

PDFNetException |

#### public void setCaching (boolean enabled)

Set the caching.

##### Parameters

enabled | whether to enable caching

##### Throws

PDFNetException |

#### public void setCancel (boolean cancel)

Signals the rendering thread whether to stop or not. This method can be used to signal the rendering thread to stop when passing true. When passing false the rendering thread will not be affected.

Note: This call affects only the current rendering thread.

##### Parameters

cancel | whether to cancel or not the rendering thread

##### Throws

PDFNetException |

#### public void setColorPostProcessColors (int white_color, int black_color)

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. This mode will map the brightness of the original rasterized bitmap to a gradient between white_color and black_color

##### Parameters

white_color | the white color of page
black_color | the black color of page

##### Throws

PDFNetException |

#### public void setColorPostProcessMapFile (Filter image_file_contents)

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. This mode will map the brightness of the original rasterized bitmap to a gradient in image_file_contents from left to right

##### Parameters

image_file_contents | is a filter with image file contents

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

#### 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

##### Throws

PDFNetException |

#### public void setImageSmoothing (boolean smoothing_enabled)

Set the image smoothing.

##### Parameters

smoothing_enabled | whether to enable image smoothing

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

#### 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

##### Throws

PDFNetException |

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

##### Throws

PDFNetException |

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