PdfPreview Object

Overview

Introduced in Version 2.0, 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.

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

Member List

Properties


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

ImageItems As PdfRects (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.


Log As String (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.


TextItems As PdfRects (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.


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

Methods


Function ExtractImage(Index As Integer) As PdfPreview

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 Nothing (null) if Index exceeds the number of images on the page.

For more information, see Section 17.5 - Image Extraction.


Function Save(Path As String, Optional Overwrite = True) As String

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.


Sub SaveHttp(DispHeader As String)

Sends the PNG image to an HTTP stream. SaveHttp can only be called in an ASP or ASP.NET environment as it internally uses ASP'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.


Function SaveToMemory() As Variant
Saves the image to a memory array. This method is useful for saving the images in the database as blobs.

Sub SendToPrinter(Printer As String, Optional Param As Variant)

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.