|
#include <PDFDraw.h>
Public Types | |
| enum | PixelFormat { e_rgba, e_bgra, e_rgb, e_bgr, e_gray } |
Public Member Functions | |
| PDFDraw (double dpi=92) | |
| PDFDraw constructor and destructor. | |
| ~PDFDraw () | |
| void | SetRasterizerType (PDFRasterizer::Type type) |
| Sets the core graphics library used for rasterization and rendering. | |
| void | SetDPI (double dpi) |
| Sets the output image resolution. | |
| void | 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. | |
| void | SetPageBox (Page::Box region) |
| Selects the page box/region to rasterize. | |
| void | SetFlipYAxis (bool flip_y) |
| Flips the vertical (i.e. | |
| void | SetRotate (Page::Rotate r) |
| Sets the rotation value for this page. | |
| void | SetDrawAnnotations (bool render_annots) |
| Enable or disable annotation and forms rendering. | |
| void | SetAntiAliasing (bool enable_aa) |
| Enable or disable anti-aliasing. | |
| void | SetImageSmoothing (bool smoothing_enabled=true) |
| Enable or disable image smoothing. | |
| void | SetCaching (bool enabled=true) |
| Enables or disables caching. | |
| void | SetGamma (double exp) |
| Sets the gamma factor used for anti-aliased rendering. | |
| void | SetOCGContext (OCG::Context *ctx) |
| Sets the Optional Content Group (OCG) context that should be used when rendering the page. | |
| void | 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. | |
| void | DrawInRect (Page &page, void *hdc, const Rect &rect) |
| Gets a GDI+ bitmap for the given page. | |
| const UChar * | GetBitmap (Page page, int &out_width, int &out_height, int &out_stride, double &out_dpi, PixelFormat pix_fmt=e_bgra) |
| Gets the raw rasterized image data for the given image. | |
| void | SetErrorReportProc (PDFRasterizer::ErrorReportProc error_proc, void *data) |
| Sets the error handling function to be called in case an error is encountered during page rendering. | |
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::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::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.
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.
| 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::SetPageBox | ( | Page::Box | region | ) |
| 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::SetRotate | ( | Page::Rotate | r | ) |
Sets the rotation value for this page.
| angle | Rotation value to be set for a given page. Must be one of the Page::Rotate values. |
| 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::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).
Anti-aliasing is enabled by default.
| void pdftron::PDF::PDFDraw::SetImageSmoothing | ( | bool | smoothing_enabled = true |
) |
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. image smoothing is enabled. |
| 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::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. |
| 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::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'). |
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: |
| Output Format | Parameter/Key | Description/Value | Example |
| JPEG | Quality | 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. | See the Example 2 in PDFDraw sample project. |
Gets a GDI+ bitmap for the given page.
| page | The source PDF page. |
this method is only supported on Windows platforms. If your application is running on a Windows platform, you can select GDI+ rasterizer with SetRasterizerType() and e_GDIPlus type.
| 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. |
| 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 | |||
| ) |
Gets 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 BGRA. |
| 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'. |