PdfPreview Object

Overview

Introduced in Version 2.6, the PdfPreview object implements the PDF-to-image conversion functionality. An instance of the PdfPreview object is created via the PdfPage.ToImage method and represents the rasterized image of the page from which it is created. The image in PNG format can be saved to disk, memory or an HTTP stream via the methods Save, SaveToMemory and SaveHttp, respectively. This object can also be used for image extraction and automatic printing.

For more information about the PDF-to-image conversion functionality, see Chapter 17 - PDF-to-Image Conversion>.

Member List

Properties


int Height (Read-only)
Returns the pixel height of the resultant PNG image.

PdfRects ImageItems (Read-only)

Returns a collection of PdfRect objects each representing an image within this document. Via various properties of the PdfRect object, data such as dimensions, displacement, scaling factors and other parameters can be obtained about each image in the document. This collection is only populated if the PdfPage.ToImage method is called with the ImageInfo parameter set to True. This property was introduced in Version 3.6.

For more information, see Section 17.8 - Image Replacement.


string Log (Read-only)

Returns a double-CRLF separated list of errors encountered during the PDF-to-image conversion process. The parameter Debug=True needs to be used in the ToImage method to enable error logging. For more information, see Section 17.3 - Error Log.

As of Version 3.6, when this instance of the PdfPreview object represents an extacted image, this property returns the inner object ID of this image. This is useful for image replacement purposes. For more information, see Section 17.8 - Image Replacement.


PdfRects TextItems (Read-only)

Returns a collection of PdfRect objects each representing a text fragment obtained during structured text extraction. This collection is only populated if the PdfPage.ToImage method is called with a non-zero ExtractText parameter. This property was introduced in Version 2.8.

For more information, see Section 17.7 - Structured Text Extraction.


int Width (Read-only)
Returns the pixel width of the resultant PNG image.

Methods


PdfPreview ExtractImage(int Index)

Extracts an image specified via 1-based Index from the PDF page from which the current PdfPreview object was created. Returns a new instance of the PdfPreview object representing the extracted image. Returns null if Index exceeds the number of images on the page.

For more information, see Section 17.5 - Image Extraction.


string Save(string Path)
string Save(string Path, bool Overwrite)

Saves the resultant PNG image to disk, returns the file name under which the image was saved (without a path).

Path specifies the full file path.

Overwrite is an optional argument specifying whether a file under the same name should be overwritten (if set to True or omitted) or a unique filename should be generated to avoid overwriting an existing file (if set to False). True by default.

Returns the filename (without the path) under which this image ends up being saved.


string SaveCore(string Path, bool Overwrite)

Same as Save but compatible with .NET Core. Only supports the PNG format.


Sub SaveHttp(string DispHeader)
Sub SaveHttp(string DispHeader, ImageFormat Format)

Sends the PNG image to an HTTP stream. SaveHttp can only be called in an ASP.NET environment as it internally uses ASP.NET's Response.BinaryWrite method.

DispHeader specifies the Content-Disposition header to be included in the HTTP stream. This header carries the file name information to be presented to the user when the file is saved to disk on the client machine. This argument has to be in the following two formats:

"filename=somename.png"

or

"attachment; filename=somename.png"

The latter prompts the user to save the file to disk instead of opening it in-place in the browser.

Format is an instance of the .NET System.Drawing.Imaging.Format class and specifies the format the image is to be saved in. If this parameter is not specified, the image is saved in PNG format.


void SaveHttpCore(string DispHeader)

Same as SaveHttp but compatible with .NET Core. Only supports the PNG format.


byte [] SaveToMemory()
byte [] SaveToMemory(ImageFormat Format)

Saves the image to a memory array of bytes. This method is useful for saving the images in the database as blobs.

Format is an instance of the .NET System.Drawing.Imaging.Format class and specifies the format the image is to be saved in. If this parameter is not specified, the image is saved in PNG format.


byte [] SaveToMemoryCore()

Same as SaveToMemory but compatible with .NET Core. Only supports the PNG format.


void SendToPrinter(string Printer, object Param)

Sends the underlying page image to a printer. Printer is a network printer name, such as "\\192.168.1.2\HP LaserJet 6P". As of Version 2.6.0.3, if Printer is set to an empty string, the default printer name for the current machine is used. Param is a PdfParam object or parameter string.

The following optional parameters are supported:

  • Stretch - if set to True, the image is stretched to cover the entire print area. False by default.
  • ScaleX, ScaleY - a number greater than 0. Specifies the scaling factor when Stretch is set to True. A value greater than 1 increases the image, less than 1 decreases it. Ignored when Stretch is False.

For more information, see Section 17.6 - Printing.

This method was introduced in Version 2.1.