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: PDFNet.dll
Syntax
public class PDFRasterizer : IDisposable
Constructors
PDFRasterizer()
empty PDFRasterizer
constructor
Declaration
public PDFRasterizer()
PDFRasterizer(Type)
instantiates PDFRasterizer
with specified type
Declaration
public PDFRasterizer(PDFRasterizer.Type type)
Parameters
Type | Name | Description |
---|---|---|
PDFRasterizer.Type | type | PDFRasterizer type |
Properties
Cancel
Gets or sets whether rasterization should be cancelled.
Declaration
public bool Cancel { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
CancelRendering()
Cancel the rendering in progress.
Declaration
public void CancelRendering()
Remarks
In order to start rendering again, set the property Cancel to false
Dispose()
Releases all resources used by the PDFRasterizer.
Declaration
public override sealed void Dispose()
Dispose(bool)
Declaration
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0)
Parameters
Type | Name | Description |
---|---|---|
bool | A_0 |
~PDFRasterizer()
Declaration
protected ~PDFRasterizer()
GetColorPostProcessMode()
Declaration
public PDFRasterizer.ColorPostProcessMode GetColorPostProcessMode()
Returns
Type | Description |
---|---|
PDFRasterizer.ColorPostProcessMode | the current color post processing mode. |
GetRasterizerType()
Gets the type of current rasterizer.
Declaration
public PDFRasterizer.Type GetRasterizerType()
Returns
Type | Description |
---|---|
PDFRasterizer.Type | the type of current rasterizer. |
Remarks
This method is deprecated, since the GDI+ rasterizer itself is deprecated and will be removed in a future version of PDFNet. It is strongly recommended to use the built-in rasterizer and to use the XPS print path where vector conversion is needed.
Rasterize(Page, byte[], int, int, int, int, bool, Matrix2D)
Draws the page into a given memory buffer.
Declaration
public void Rasterize(Page page, byte[] out_image_buffer, int width, int height, int stride, int num_comps, bool demult, Matrix2D device_mtx)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to rasterize. |
byte[] | out_image_buffer | The output memory buffer. The buffer must contain at least (stride * height) bytes. |
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. |
Rasterize(Page, byte[], int, int, int, int, bool, Matrix2D, Rect)
Draws the page into a given memory buffer.
Declaration
public void Rasterize(Page page, byte[] out_image_buffer, 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. |
byte[] | out_image_buffer | The output memory buffer. The buffer must contain at least (stride * height) bytes. |
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 | Defines 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. |
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[] | The output memory buffer. |
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 | Defines 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[] | The output memory buffer. |
RasterizeSeparations(Page, int, int, Matrix2D, Rect, bool)
Draws the page into a given memory buffer (Separation)
Declaration
public Separation[] RasterizeSeparations(Page page, int width, int height, Matrix2D device_mtx, Rect clip, bool cancel)
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). |
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. |
bool | cancel | An optional variable that can be used to stop the rendering thread. |
Returns
Type | Description |
---|---|
Separation[] | The output memory buffer. |
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 |
SetColorPostProcessMode(ColorPostProcessMode)
Draws the page into a given memory buffer. 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.
Declaration
public void SetColorPostProcessMode(PDFRasterizer.ColorPostProcessMode mode)
Parameters
Type | Name | Description |
---|---|---|
PDFRasterizer.ColorPostProcessMode | mode | mode is the specific transform to be applied. |
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)
Declaration
public void SetOCGContext(Context ctx)
Parameters
Type | Name | Description |
---|---|---|
Context | ctx |
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
public void SetRasterizerType(PDFRasterizer.Type type)
Parameters
Type | Name | Description |
---|---|---|
PDFRasterizer.Type | type | PDFRasterizer type |
Remarks
This method is deprecated, since the GDI+ rasterizer itself is deprecated and will be removed in a future version of PDFNet. It is strongly recommended to use the built-in rasterizer and to use the XPS print path where vector conversion is needed.
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. |