Class PDFRasterizer
PDFRasterizer is a low-level PDF rasterizer. The main purpose of this class is to convert PDF pages to raster images (or bitmaps). 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 use PDF.PDFViewCtrl instead.
Implements
Inherited Members
Namespace: pdftron.PDF
Assembly: PDFTronDotNet.dll
Syntax
public class PDFRasterizer : IDisposable
Constructors
PDFRasterizer()
empty PDFRasterizer
constructor
Declaration
public PDFRasterizer()
PDFRasterizer(Type)
instantiates PDFRasterizer
with specified type
Declaration
[Obsolete("Deprecated, will be removed in the next update.")]
public PDFRasterizer(PDFRasterizer.Type type)
Parameters
Type | Name | Description |
---|---|---|
PDFRasterizer.Type | type | PDFRasterizer type |
Methods
CancelRendering()
Cancel the rendering in progress.
Declaration
public void CancelRendering()
Destroy()
Declaration
public void Destroy()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
~PDFRasterizer()
Releases all resources used by the PDFRasterizer
Declaration
protected ~PDFRasterizer()
GetRasterizerType()
Gets the type of current rasterizer.
Declaration
[Obsolete("Deprecated, will be removed in the next update.")]
public PDFRasterizer.Type GetRasterizerType()
Returns
Type | Description |
---|---|
PDFRasterizer.Type | the type of current rasterizer. |
Rasterize(Page, int, int, int, int, bool, Matrix2D)
Draws the page into a given memory buffer.
Declaration
public byte[] Rasterize(Page page, int width, int height, int stride, int num_comps, bool demult, Matrix2D device_mtx)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to rasterize. |
int | width | The width of the target image in pixels. |
int | height | The height of the target image in pixels (the number of rows). |
int | 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. |
int | 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. |
bool | demult | Specifies if the alpha is de-multiplied from the resulting color components. |
Matrix2D | 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. |
Returns
Type | Description |
---|---|
byte[] |
Rasterize(Page, int, int, int, int, bool, Matrix2D, Rect)
Draws the page into a given memory buffer.
Declaration
public byte[] Rasterize(Page page, int width, int height, int stride, int num_comps, bool demult, Matrix2D device_mtx, Rect clip)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to rasterize. |
int | width | The width of the target image in pixels. |
int | height | The height of the target image in pixels (the number of rows). |
int | 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. |
int | 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. |
bool | demult | Specifies if the alpha is de-multiplied from the resulting color components. |
Matrix2D | 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. |
Rect | 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
Type | Description |
---|---|
byte[] |
Examples
float drawing_scale = 2:
Common.Matrix2D mtx(drawing_scale, 0, 0, drawing_scale, 0, 0);
PDF.Rect bbox(page.GetMediaBox());
bbox.Normalize();
int width = int(bbox.Width() * drawing_scale);
int height = int(bbox.Height() * drawing_scale);
// Stride is represented in bytes and is aligned on 4 byte
// boundary so that you can render directly to GDI bitmap.
// A negative value for stride can be used to flip the image
// upside down.
int comps = 4; // for BGRA
int stride = ((width * comps + 3) / 4) * 4;
// buf is a memory buffer containing at least (stride*height) bytes.
memset(ptr, 0xFF, height*stride); // Clear the background to opaque white paper color.
PDFRasterizer rast;
rast.Rasterize(page, buf, width, height, stride, 4, false, mtx);
SetAntiAliasing(bool)
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.
Declaration
public void SetAntiAliasing(bool enable_aa)
Parameters
Type | Name | Description |
---|---|---|
bool | enable_aa | true to enable anti-aliasing. |
SetCaching(bool)
Sets the caching.
Declaration
public void SetCaching(bool enabled)
Parameters
Type | Name | Description |
---|---|---|
bool | enabled | the new caching |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
SetDrawAnnotations(bool)
Enable or disable annotation and forms rendering. By default, annotations and forms are rendered.
Declaration
public void SetDrawAnnotations(bool render_annots)
Parameters
Type | Name | Description |
---|---|---|
bool | render_annots | True to draw annotations, false otherwise. |
SetGamma(double)
Sets the gamma factor used for anti-aliased rendering.
Declaration
public void SetGamma(double exp)
Parameters
Type | Name | Description |
---|---|---|
double | exp | exponent value of gamma function. Typical values are in the range from 0.1 to 3. |
Remarks
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). Gamma correction is used only in the built-in rasterizer.
SetHighlightFields(bool)
Enable or disable highlighting form fields. Default is disabled.
Declaration
public void SetHighlightFields(bool highlight_fields)
Parameters
Type | Name | Description |
---|---|---|
bool | highlight_fields | true to highlight, false otherwise. |
SetImageSmoothing(bool, bool)
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.image smoothing is enabled by default.
Declaration
public void SetImageSmoothing(bool smoothing_enabled, bool hq_image_resampling)
Parameters
Type | Name | Description |
---|---|---|
bool | smoothing_enabled | whether to enable image smoothing |
bool | hq_image_resampling | whether to use a higher quality (but slower) smoothing algorithm |
Remarks
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.
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
SetOCGContext(Context)
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.
Declaration
public void SetOCGContext(Context ctx)
Parameters
Type | Name | Description |
---|---|---|
Context | ctx | Optional Content Group (OCG) context, or NULL if the rasterizer should render all content on the page. |
SetOverprint(OverprintPreviewMode)
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 for only PDF/X files.
Declaration
public void SetOverprint(PDFRasterizer.OverprintPreviewMode op)
Parameters
Type | Name | Description |
---|---|---|
PDFRasterizer.OverprintPreviewMode | op | e_op_on: always enabled; e_op_off: always disabled; e_op_pdfx_on: enabled for PDF/X files only. |
SetPathHinting(bool)
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. This option is turned on by default.
Declaration
public void SetPathHinting(bool enable_ph)
Parameters
Type | Name | Description |
---|---|---|
bool | enable_ph | whether to enable path hinting. |
SetPrintMode(bool)
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.
Declaration
public void SetPrintMode(bool is_printing)
Parameters
Type | Name | Description |
---|---|---|
bool | is_printing | set to true is the page should be rendered in print mode. By default, print mode flag is set to false. |
SetRasterizerType(Type)
Sets rasterizer to the specified type
Declaration
[Obsolete("Deprecated, will be removed in the next update.")]
public void SetRasterizerType(PDFRasterizer.Type type)
Parameters
Type | Name | Description |
---|---|---|
PDFRasterizer.Type | type | PDFRasterizer type |
SetThinLineAdjustment(bool, bool)
Set thin line adjustment parameters.
Declaration
public void SetThinLineAdjustment(bool pixel_grid_fit, bool stroke_adjust)
Parameters
Type | Name | Description |
---|---|---|
bool | 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. |
bool | 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. |