#include <PDFDraw.h>
Public Types | |
enum | PixelFormat { e_rgba, e_bgra, e_rgb, e_bgr, e_gray, e_gray_alpha, e_cmyk } |
Public Member Functions | |
PDFDraw (double dpi=92) | |
~PDFDraw () | |
void | SetRasterizerType (PDFRasterizer::Type type) |
void | SetDPI (double dpi) |
void | SetImageSize (int width, int height, bool preserve_aspect_ratio=true) |
void | SetPageBox (Page::Box region) |
void | SetClipRect (Rect clip_rect) |
void | SetFlipYAxis (bool flip_y) |
void | SetRotate (Page::Rotate r) |
void | SetDrawAnnotations (bool render_annots) |
void | SetHighlightFields (bool highlight_fields) |
void | SetDrawUIElements (bool draw_ui_elements) |
void | SetAntiAliasing (bool enable_aa) |
void | SetPathHinting (bool enable_hinting) |
void | SetThinLineAdjustment (bool pixel_grid_fit, bool stroke_adjust) |
void | SetThinLineScaling (double scaling) |
void | SetImageSmoothing (bool smoothing_enabled=true, bool hq_image_resampling=false) |
void | SetCaching (bool enabled=true) |
void | SetGamma (double exp) |
void | SetOCGContext (OCG::Context *ctx) |
void | SetPrintMode (bool is_printing) |
void | SetDefaultPageColor (UInt8 r, UInt8 g, UInt8 b) |
void | SetPageTransparent (bool is_transparent) |
void | SetOverprint (PDFRasterizer::OverprintPreviewMode op) |
void | Export (Page page, const UString &filename, const char *format="PNG", SDF::Obj encoder_params=0) |
void | Export (Page page, Filters::Filter &stream, const char *format="PNG", SDF::Obj encoder_params=0) |
void | DrawInRect (Page &page, void *hdc, const Rect &rect) |
const BitmapInfo | GetBitmap (Page page, PixelFormat pix_fmt=e_bgra, bool demult=false) |
std::vector< Separation > | GetSeparationBitmaps (Page page) |
const UChar * | GetBitmap (Page page, int &out_width, int &out_height, int &out_stride, double &out_dpi, PixelFormat pix_fmt=e_bgra, bool demult=false) |
void | SetErrorReportProc (PDFRasterizer::ErrorReportProc error_proc, void *data) |
void | SetColorPostProcessMode (PDFRasterizer::ColorPostProcessMode mode) |
void | Destroy () |
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.
pdftron::PDF::PDFDraw::PDFDraw | ( | double | dpi = 92 | ) |
PDFDraw constructor and destructor
dpi | - 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. |
pdftron::PDF::PDFDraw::~PDFDraw | ( | ) |
void pdftron::PDF::PDFDraw::Destroy | ( | ) |
Frees the native memory of the object.
Returns a GDI+ bitmap for the given page.
page | The source PDF page. |
page | The source PDF page. |
hdc | Device context (i.e. HDC structure). |
rect | The rectangle in the device context inside of which the page will be drawn. |
void pdftron::PDF::PDFDraw::Export | ( | Page | page, |
const UString & | filename, | ||
const char * | format = "PNG" , |
||
SDF::Obj | encoder_params = 0 |
||
) |
A utility method to export the given PDF page to an image file.
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:
By default, the function exports to PNG.
encoder_params | - 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); |
void pdftron::PDF::PDFDraw::Export | ( | Page | page, |
Filters::Filter & | stream, | ||
const char * | format = "PNG" , |
||
SDF::Obj | encoder_params = 0 |
||
) |
const BitmapInfo pdftron::PDF::PDFDraw::GetBitmap | ( | Page | page, |
PixelFormat | pix_fmt = e_bgra , |
||
bool | demult = false |
||
) |
Returns the raw rasterized image data for the given image.
page | The source PDF page. |
pix_fmt | - Optional parameter used to specify the desired pixel format. The default pixel format is e_bgra. |
demult | - Specifies if the alpha is de-multiplied from the resulting color components. This parameter is only used for e_rgba, e_bgra, e_gray_alpha formats. |
const UChar* pdftron::PDF::PDFDraw::GetBitmap | ( | Page | page, |
int & | out_width, | ||
int & | out_height, | ||
int & | out_stride, | ||
double & | out_dpi, | ||
PixelFormat | pix_fmt = e_bgra , |
||
bool | demult = false |
||
) |
Returns the raw rasterized image data for the given image.
page | The source PDF page. |
out_width | - Filled by the method. The width of the target image in pixels. |
out_height | - Filled by the method. The height of the target image in pixels (the number of rows). |
out_stride | - Filled by the method. 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). |
out_dpi | - Filled by the method. The output resolution of the image (Dots Per Inch). |
pix_fmt | - Optional parameter used to specify the desired pixel format. The default pixel format is e_bgra. |
demult | - Specifies if the alpha is de-multiplied from the resulting color components. This parameter is only used for e_rgba, e_bgra, e_gray_alpha formats. |
std::vector<Separation> pdftron::PDF::PDFDraw::GetSeparationBitmaps | ( | Page | page | ) |
Returns a vector of rasterized separations for the given image.
page | The source PDF page. |
void pdftron::PDF::PDFDraw::SetAntiAliasing | ( | bool | 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).
enable_aa | if true anti-aliasing will be enabled. Anti-aliasing is enabled by default. |
void pdftron::PDF::PDFDraw::SetCaching | ( | bool | enabled = true | ) |
Enables or disables caching. Caching can improve the rendering performance in cases where the same page will be drawn multiple times.
enabled | - if true PDFRasterizer will cache frequently used graphics objects. |
void pdftron::PDF::PDFDraw::SetClipRect | ( | Rect | clip_rect | ) |
clip the render region to the provided rect (in page space)
clip_rect | clipping rect. By default, PDFDraw will rasterize the entire page box. |
void pdftron::PDF::PDFDraw::SetColorPostProcessMode | ( | PDFRasterizer::ColorPostProcessMode | 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.
mode | is the specific transform to be applied |
Sets the default color of the page backdrop.
By default, the page color is white.
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. |
void pdftron::PDF::PDFDraw::SetDPI | ( | double | 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.
dpi | value to set the image resolution to. Higher value = higher resolution. |
void pdftron::PDF::PDFDraw::SetDrawAnnotations | ( | bool | render_annots | ) |
Enable or disable annotation and forms rendering. By default, all annotations and form fields are rendered.
render_annots | True to draw annotations, false otherwise. |
void pdftron::PDF::PDFDraw::SetDrawUIElements | ( | bool | draw_ui_elements | ) |
Enable or disable drawing ui elements. Default is disabled.
draw_ui_elements | true to draw ui elements, false otherwise. |
void pdftron::PDF::PDFDraw::SetErrorReportProc | ( | PDFRasterizer::ErrorReportProc | error_proc, |
void * | data | ||
) |
Sets the error handling function to be called in case an error is encountered during page rendering.
error_proc | Error handling callback function (or delegate in .NET) |
data | Custom data to be passed as a second parameter to 'error_proc'. |
void pdftron::PDF::PDFDraw::SetFlipYAxis | ( | bool | flip_y | ) |
Flips the vertical (i.e. Y) axis of the image.
flip_y | true to flip the Y axis, false otherwise. For compatibility with most raster formats 'flip_y' is true by default. |
void pdftron::PDF::PDFDraw::SetGamma | ( | double | exp | ) |
Sets the gamma factor used for anti-aliased rendering.
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).
void pdftron::PDF::PDFDraw::SetHighlightFields | ( | bool | highlight_fields | ) |
Enable or disable highlighting form fields. Default is disabled.
highlight_fields | true to highlight, false otherwise. |
void pdftron::PDF::PDFDraw::SetImageSize | ( | int | width, |
int | height, | ||
bool | preserve_aspect_ratio = true |
||
) |
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.
width | - The width of the image, in pixels/samples. |
height | - The height of the image, in pixels/samples. |
preserve_aspect_ratio | - True to preserve the aspect ratio, false otherwise. By default, preserve_aspect_ratio is true. |
void pdftron::PDF::PDFDraw::SetImageSmoothing | ( | bool | smoothing_enabled = true , |
bool | hq_image_resampling = false |
||
) |
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.
smoothing_enabled | True to enable image smoothing, false otherwise. |
hq_image_resampling | True to use a higher quality (but slower) smoothing algorithm image smoothing is enabled and hq_image_resampling is false. |
void pdftron::PDF::PDFDraw::SetOCGContext | ( | OCG::Context * | 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.
ctx | Optional Content Group (OCG) context, or NULL if the rasterizer should render all content on the page. |
void pdftron::PDF::PDFDraw::SetOverprint | ( | PDFRasterizer::OverprintPreviewMode | 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).
By default overprint is only enabled for PDF/X files.
op | e_op_on: always enabled; e_op_off: always disabled; e_op_pdfx_on: enabled for PDF/X files only. |
void pdftron::PDF::PDFDraw::SetPageBox | ( | Page::Box | region | ) |
void pdftron::PDF::PDFDraw::SetPageTransparent | ( | bool | is_transparent | ) |
Sets 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.
is_transparent | If true, page's backdrop color will be transparent. If false, the page's backdrop will be a opaque white. |
void pdftron::PDF::PDFDraw::SetPathHinting | ( | bool | enable_hinting | ) |
Enable or disable path hinting.
enable_hinting | 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. |
void pdftron::PDF::PDFDraw::SetPrintMode | ( | bool | 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.
is_printing | set to true if the page should be rendered in print mode. By default, print mode flag is set to false. |
void pdftron::PDF::PDFDraw::SetRasterizerType | ( | PDFRasterizer::Type | 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.
type | Rasterizer type. |
void pdftron::PDF::PDFDraw::SetRotate | ( | Page::Rotate | r | ) |
Sets the rotation value for this page.
r | Rotation value to be set for a given page. Must be one of the Page::Rotate values. |
void pdftron::PDF::PDFDraw::SetThinLineAdjustment | ( | bool | pixel_grid_fit, |
bool | stroke_adjust | ||
) |
Set thin line adjustment 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 it 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. |
void pdftron::PDF::PDFDraw::SetThinLineScaling | ( | double | scaling | ) |
This setting controls the thickness of zero-width lines when rendered. In a PDF, a line width of zero denotes the thinnest line that can be rendered at device resolution: 1 device pixel wide. However, on high-resolution devices, a single pixel can be nearly invisible.
scaling | use this setting to increase the apparent thickness of these zero-width lines. 1.0 (1 pixel wide) |