public class PDFRasterizer
extends java.lang.Object
* 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.
Modifier and Type | Field and Description |
---|---|
static int |
e_postprocess_gradient_map
The Constant e_postprocess_gradient_map.
|
static int |
e_postprocess_invert
The Constant e_postprocess_invert.
|
static int |
e_postprocess_night_mode
The Constant e_postprocess_night_mode.
|
static int |
e_postprocess_none
The Constant e_postprocess_none.
|
Constructor and Description |
---|
PDFRasterizer() |
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Frees the native memory of the object.
|
int |
getColorPostProcessMode() |
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.
|
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 |
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 |
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)
Set the 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 |
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.
|
public static final int e_postprocess_none
public static final int e_postprocess_invert
public static final int e_postprocess_gradient_map
public static final int e_postprocess_night_mode
public PDFRasterizer() throws PDFNetException
PDFNetException
public void destroy() throws PDFNetException
PDFNetException
public void setAntiAliasing(boolean enable_aa) throws PDFNetException
enable_aa
- whether to enable or disable anti-aliasingPDFNetException
public void setCancel(boolean cancel) throws PDFNetException
Note: This call affects only the current rendering thread.
cancel
- whether to cancel or not the rendering threadPDFNetException
public void setPathHinting(boolean enable_ph) throws PDFNetException
enable_ph
- whether to enable or disable path hintingPDFNetException
public void setDrawAnnotations(boolean render_annots) throws PDFNetException
render_annots
- True to draw annotations, false otherwise.PDFNetException
public void setHighlightFields(boolean highlight_fields)
highlight_fields
- true to highlight, false otherwise.public void setThinLineAdjustment(boolean pixel_grid_fit, boolean stroke_adjust)
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.public void setImageSmoothing() throws PDFNetException
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.
PDFNetException
public void setImageSmoothing(boolean smoothing_enabled) throws PDFNetException
smoothing_enabled
- whether to enable image smoothingPDFNetException
public void setImageSmoothing(boolean smoothing_enabled, boolean hq_image_resampling) throws PDFNetException
smoothing_enabled
- whether to enable image smoothinghq_image_resampling
- whether to use a higher quality (but slower) smoothing algorithmPDFNetException
public void setCaching() throws PDFNetException
PDFNetException
public void setCaching(boolean enabled) throws PDFNetException
enabled
- whether to enable cachingPDFNetException
public void setGamma(double exp) throws PDFNetException
Note: Gamma correction is used only in the built-in rasterizer.
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).PDFNetException
public void setOCGContext(Context ctx) throws PDFNetException
ctx
- Optional Content Group (OCG) context, or NULL if the
rasterizer should render all content on the page.PDFNetException
public void setPrintMode(boolean is_printing) throws PDFNetException
is_printing
- set to true if the page should be rendered in print mode.PDFNetException
public void setOverprint(int op) throws PDFNetException
op
- 0: always disabled; 1: always enabled; 2: enabled for PDF/X files only.
The default is 2.PDFNetException
public void setColorPostProcessMode(int mode)
mode
- is the specific transform to be appliedpublic int getColorPostProcessMode()
public void rasterize(Page page, int[] buffer, int width, int height, boolean demult, Matrix2D device_mtx, Rect clip) throws PDFNetException
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.PDFNetException
public byte[] rasterize(Page page, int width, int height, int stride, int num_comps, boolean demult, Matrix2D device_mtx, Rect clip) throws PDFNetException
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.PDFNetException