public class PDFDraw
extends java.lang.Object
Note: This class is available on all platforms supported by PDFNet.
Modifier and Type | Class and Description |
---|---|
class |
PDFDraw.IntBufferData |
Modifier and Type | Field and Description |
---|---|
static int |
e_bgr
The Constant e_bgr.
|
static int |
e_bgra
The Constant e_bgra.
|
static int |
e_gray
The Constant e_gray.
|
static int |
e_gray_alpha
The Constant e_gray_alpha.
|
static int |
e_postprocess_invert
The Constant e_postprocess_invert.
|
static int |
e_postprocess_none
The Constant e_postprocess_none.
|
static int |
e_rgb
The Constant e_rgb.
|
static int |
e_rgba
The Constant e_rgba.
|
Constructor and Description |
---|
PDFDraw()
PDFDraw constructor and destructor.
|
PDFDraw(double dpi)
Instantiates a new PDFDraw with specified DPI(Dots per Inch).
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Frees the native memory of the object.
|
void |
drawInRect(java.awt.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,
java.lang.String filename)
A utility method to export the given PDF page to a PNG image file.
|
void |
export(Page page,
java.lang.String filename,
java.lang.String format)
Export.
|
void |
export(Page page,
java.lang.String filename,
java.lang.String format,
Obj encoder_params)
Export.
|
java.awt.image.BufferedImage |
getBitmap(Page page)
Get the bitmap from given page
|
java.awt.image.BufferedImage |
getBitmap(Page page,
java.awt.image.BufferedImage image)
Get a Java Image for the given page.
|
byte[] |
getByteBuffer(Page page) |
PDFDraw.IntBufferData |
getIntBuffer(Page page) |
void |
setAntiAliasing(boolean enable_aa)
Enable or disable anti-aliasing.
|
void |
setCaching()
Enables or disables caching.
|
void |
setCaching(boolean enabled)
Set the caching.
|
void |
setColorPostProcessMode(int mode)
Set the color post processing transformation.
|
void |
setDefaultPageColor(byte r,
byte g,
byte b)
Sets the default color of the page backdrop.
|
void |
setDPI(double dpi)
Set the output image resolution.
|
void |
setDrawAnnotations(boolean render_annots)
Enable or disable annotation and forms rendering.
|
void |
setErrorReportProc(ErrorReportProc error_proc,
java.lang.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()
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 |
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.
|
public static final int e_postprocess_none
public static final int e_postprocess_invert
public static final int e_rgba
public static final int e_bgra
public static final int e_rgb
public static final int e_bgr
public static final int e_gray
public static final int e_gray_alpha
public PDFDraw() throws PDFNetException
PDFNetException
public PDFDraw(double dpi) throws PDFNetException
dpi
- the input DPIPDFNetException
public void destroy() throws PDFNetException
PDFNetException
public void setRasterizerType(int type) throws PDFNetException
type
- Rasterizer type.PDFNetException
public void setDPI(double dpi) throws PDFNetException
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.
dpi
- the new DPIPDFNetException
public void setImageSize(int width, int height) throws PDFNetException
width
- - The width of the image, in pixels/samples.height
- - The height of the image, in pixels/samples.PDFNetException
public void setImageSize(int width, int height, boolean preserve_aspect_ratio) throws PDFNetException
width
- image widthheight
- image heightpreserve_aspect_ratio
- whether to preserve aspect ratioPDFNetException
public void setPageBox(int region) throws PDFNetException
region
- Page box to rasterize. By default, PDFDraw will rasterize page
crop box.PDFNetException
public void setFlipYAxis(boolean flip_y) throws PDFNetException
flip_y
- true to flip the Y axis, false otherwise. For compatibility
with most raster formats 'flip_y' is true by default.PDFNetException
public void setRotate(int r) throws PDFNetException
Note: This method is used only for drawing purposes and it does not modify the document (unlike Page::SetRotate()).
r
- the new rotation valuePDFNetException
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 setAntiAliasing(boolean enable_aa) throws PDFNetException
enable_aa
- whether to enable or disable anti-aliasingPDFNetException
public void setPathHinting(boolean enable_ph) throws PDFNetException
enable_ph
- whether to enable or disable path hintingPDFNetException
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 setDefaultPageColor(byte r, byte g, byte b) throws PDFNetException
Note: If the page backdrop is set to transparent, the page backdrop will be ignored.
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.PDFNetException
public void setPageTransparent(boolean is_transparent) throws PDFNetException
Note: If page transparency is enabled, the alpha channel will be preserved when the image is exported as PNG, TIFF, or RAW.
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.PDFNetException
public void setColorPostProcessMode(int mode)
mode
- is the specific transform to be appliedpublic 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 export(Page page, java.lang.String filename) throws PDFNetException
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').PDFNetException
public void export(Page page, java.lang.String filename, java.lang.String format) throws PDFNetException
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.PDFNetException
public void export(Page page, java.lang.String filename, java.lang.String format, Obj encoder_params) throws PDFNetException
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.PDFNetException
public java.awt.image.BufferedImage getBitmap(Page page)
page
- the input pagepublic java.awt.image.BufferedImage getBitmap(Page page, java.awt.image.BufferedImage image)
page
- The source PDF page.image
- The input imagepublic byte[] getByteBuffer(Page page)
public PDFDraw.IntBufferData getIntBuffer(Page page)
public void drawInRect(java.awt.Graphics g, Page page, int x, int y, int width, int height)
g
- Java Graphics objectpage
- The source PDF page.x
- the xy
- the ywidth
- the widthheight
- the heightpublic void setErrorReportProc(ErrorReportProc error_proc, java.lang.Object data) throws PDFNetException
error_proc
- Error handling callback function (or delegate in .NET)data
- Custom data to be passed as a second parameter to
'error_proc'.PDFNetException