Show / Hide Table of Contents

Class PDFDraw

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.

Inheritance
object
PDFDraw
Implements
IDisposable
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: pdftron.PDF
Assembly: PDFNet.dll
Syntax
public class PDFDraw : IDisposable
Remarks

This class is available on all platforms supported by PDFNet.

Constructors

PDFDraw()

PDFDraw constructor and destructor.

Declaration
public PDFDraw()
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

PDFDraw(double)

Instantiates a new pDF draw.

Declaration
public PDFDraw(double dpi)
Parameters
Type Name Description
double dpi

the dpi

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Methods

Dispose()

Releases all resources used by the PDFDraw

Declaration
public override sealed void Dispose()

Dispose(bool)

Declaration
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0)
Parameters
Type Name Description
bool A_0

DrawInRect(Page, Graphics, Rect)

Draws the contents of the page to a given Graphics object.

Declaration
public void DrawInRect(Page page, Graphics gr, Rect rect)
Parameters
Type Name Description
Page page

The source PDF page.

Graphics gr

Device context

Rect rect

The rectangle in the device context inside of which the page will be drawn.

Remarks

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.

DrawInRect(Page, IntPtr, Rect)

Draws the contents of the page to a given Graphics object.

Declaration
public void DrawInRect(Page page, IntPtr dc, Rect rect)
Parameters
Type Name Description
Page page

The source PDF page.

IntPtr dc

Device context (i.e. HDC structure).

Rect rect

The rectangle in the device context inside of which the page will be drawn.

Remarks

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.

Export(Page, string)

A utility method to export the given PDF page to an image file.

Declaration
public void Export(Page page, string filename)
Parameters
Type Name Description
Page page

The source PDF page.

string filename
  • The name of the output image file. The filename should include the extension suffix (e.g. 'c:/output/myimage.png').
Remarks

By default, the function exports to PNG.. The file format of the output image. Currently supported formats are:

  • RAW format. There are four possibilities: e_rgba - if transparent and color page; e_gray_alpha - if transparent and gray page; e_rgb - if opaque and color page; e_gray - if opaque and gray page.
  • Bitmap image format (BMP)
  • Joint Photographic Experts Group (JPEG) image format
  • 24-bit W3C Portable Network Graphics (PNG) image format
  • 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.
  • Tag Image File Format (TIFF) image format.
  • Tag Image File Format (TIFF) image format (with 8-bit pallete).
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Export(Page, string, string)

Export.

Declaration
public void Export(Page page, string filename, string format)
Parameters
Type Name Description
Page page

the page

string filename

the filename

string format

the format

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

Export(Page, string, string, Obj)

Export.

Declaration
public void Export(Page page, string filename, string format, Obj encoder_hints)
Parameters
Type Name Description
Page page

the page

string filename

the filename

string format

the format

Obj encoder_hints

the encoder_params

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

~PDFDraw()

Declaration
protected ~PDFDraw()

GetBitmap(byte*, int, int, int, double, PixelFormat)

Gets the bitmap.

Declaration
public static Bitmap GetBitmap(byte* buf, int width, int height, int stride, double dpi, PixelFormat pixfmt)
Parameters
Type Name Description
byte* buf

An unmanaged buffer of image data

int width

Width of buf

int height

Height of buf

int stride

Stride of buf

double dpi

Resolution of buf

PixelFormat pixfmt

Pixel format of buf

Returns
Type Description
Bitmap

the bitmap

GetBitmap(Page)

Gets the bitmap.

Declaration
public Bitmap GetBitmap(Page page)
Parameters
Type Name Description
Page page

the page

Returns
Type Description
Bitmap

the bitmap

GetBitmapSource(Page)

Gets the bitmap. (WPF BitmapSource)

Declaration
public BitmapSource GetBitmapSource(Page page)
Parameters
Type Name Description
Page page

the page

Returns
Type Description
BitmapSource

the bitmap (WPF BitmapSource)

GetSeparationBitmaps(Page)

Gets the Separations from the page

Declaration
public Separation[] GetSeparationBitmaps(Page page)
Parameters
Type Name Description
Page page

the page

Returns
Type Description
Separation[]

Separations array

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

whether 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

SetClipRect(Rect)

Clip the render region to the provided rect (in page space)

Declaration
public void SetClipRect(Rect clip_rect)
Parameters
Type Name Description
Rect clip_rect

Clipping rect. By default, PDFDraw will rasterize the entire page box.

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.

SetDPI(double)

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.

Declaration
public void SetDPI(double dpi)
Parameters
Type Name Description
double dpi

the new dPI

Remarks
            <p>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.

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.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetDefaultPageColor(Color)

Sets the default color of the page backdrop.

Declaration
public void SetDefaultPageColor(Color c)
Parameters
Type Name Description
Color c

The color (RGB) to set.

SetDrawAnnotations(bool)

Enable or disable annotation and forms rendering. By default, all annotations and form fields are rendered.

Declaration
public void SetDrawAnnotations(bool render_annots)
Parameters
Type Name Description
bool render_annots

True to draw annotations, false otherwise.

SetFlipYAxis(bool)

Flips the vertical (i.e. Y) axis of the image.

Declaration
public void SetFlipYAxis(bool flip_y)
Parameters
Type Name Description
bool flip_y

true to flip the Y axis, false otherwise. For compatibility with most raster formats 'flip_y' is true by default.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

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.

SetImageSize(int, int)

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.

Declaration
public void SetImageSize(int width, int height)
Parameters
Type Name Description
int width
  • The width of the image, in pixels/samples.
int height
  • The height of the image, in pixels/samples.
Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetImageSize(int, int, bool)

Sets the image size.

Declaration
public void SetImageSize(int width, int height, bool preserve_aspect_ratio)
Parameters
Type Name Description
int width

the width

int height

the height

bool preserve_aspect_ratio

the preserve_aspect_ratio

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

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.

SetPageBox(Box)

Selects the page box/region to rasterize.

Declaration
public void SetPageBox(Page.Box region)
Parameters
Type Name Description
Page.Box region

Page box to rasterize. By default, PDFDraw will rasterize page crop box.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetPageTransparent(bool)

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.

Declaration
public void SetPageTransparent(bool is_transp)
Parameters
Type Name Description
bool is_transp

If true, page's backdrop color will be transparent. If false, the page's backdrop will be a opaque white.

Remarks

If true, page's backdrop color will be transparent. If false, the page's backdrop will be a opaque white.

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 if the page should be rendered in print mode. By default, print mode flag is set to false.

SetRasterizerType(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.

Declaration
public void SetRasterizerType(PDFRasterizer.Type type)
Parameters
Type Name Description
PDFRasterizer.Type type

Rasterizer 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 default built-in rasterizer and to use the XPS print path where vector conversion is needed.

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

SetRotate(Rotate)

Sets the rotation value for this page.

Declaration
public void SetRotate(Page.Rotate r)
Parameters
Type Name Description
Page.Rotate r

the new rotate

Remarks

This method is used only for drawing purposes and it does not modify the document (unlike Page::SetRotate()).

Exceptions
Type Condition
PDFNetException

PDFNetException the PDFNet exception

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.

Implements

IDisposable
In This Article
Back to top Generated by DocFX