Persits Software, Inc. Web Site
 Navigator:  Home |  Object Reference |  PdfDocument
PdfFont PdfDest
  PdfDocument Object
PdfDocument is a major object representing a new or existing PDF document. An instance of PdfDocument is creatable via PdfManager's CreateDocument method as well as OpenDocument/OpenDocumentBinary methods.

Properties Methods
Author
CreationDate
Creator
Encrypted
Filename
Fonts
Form
ID
KeyLength
Keywords
Mac
MetaData
ModDate
OpenAction
OriginalFilename
OriginalPath
OriginalVersion
Outline
OwnerPassword
OwnerPasswordUsed
PageLayout
PageMode
Pages
Path
Permissions
Producer
Subject
Title
UserPassword
Version
AppendDocument
Close
CreateAction
CreateDest
CreateGraphics
CreateTable
Encrypt
ExtractPages
ImportFromUrl
OpenImage
OpenImageBinary
Save
SaveHttp
SaveToMemory
SetViewerPrefs
Sign
VerifySignature

Properties


Author As String (Read/Write)

Returns or specifies the document's author (usually the name of the person who created the document).

CreationDate As Date (Read/Write)

Returns or specifies the date/time the document was created.

Creator As String (Read/Write)

Returns or specifies the document's creator. If the document was converted from to PDF from another format, this property returns the name of the application that created the original document.

Encrypted As Boolean (Read-only)

Returns True is the document is encrypted.

Filename As String (Read-only)

Returns the filename (without a path) under which this document was saved via the Save method. This property is particularly useful when the Save method is called with the Overwrite option set to False and the actual filename may differ from the desired filename passed to the Save method. If the document was saved using SaveToMemory or SaveHttp, this property returns an empty string.

Fonts As PdfFonts (Read-only)

Returns the PdfFonts collection which enables you to obtain a PdfFont object to be passed to text-drawing methods such as Canvas.DrawText. For more information, see Chapter 6 - Text and Fonts.

Form As PdfForm (Read-only)

Returns the PdfForm collection of PdfAnnot objects representing interactive form fields placed on this document. For more information, see Chapter 11 - Forms.

ID As String (Read-only)

Returns this document's Hex-encoded ID which is usually a random 16-byte binary sequence, such as "244F19CCDF3988289B47B29585AD9A12".

KeyLength As Long (Read-only)

If this document is encrypted, returns the key length, such as 40 or 128. Returns 0 otherwise.

Keywords As String (Read/Write)

Returns or specifies keywords associated with this document.

Mac As Boolean (Read-only)

Returns True if this is an existing document and there are indications the file contains a MacBinary header. Returns False in all other cases.

MetaData As String (Read/Write)

Returns or specifies this document's XML-based metadata string. For more information, see Section 12.3 - Metadata.

ModDate As Date (Read/Write)

Returns or specifies the date/time the document was most recently modified.

OpenAction As Object (Read/Write)

Specifies a PdfDest or PdfAction object to be used when the document is opened. Use this property if you need the document to fit the window in a particular way upon opening, or perform a certain action (such as execute a script). For more information about destinations and actions, see Section 10.1 - Destinations and Section 10.4 - Actions, respectively.

Usage:

Doc.OpenAction = Doc.Pages(1).CreateDest("Fit=true")

Doc.OpenAction = Doc.CreateAction("type=JavaScript", "this.print(true)" )


OriginalFilename As String (Read-only)

Returns this document's original filename (without a path) if the document was opened using Pdf.OpenDocument. If this is a new document, or if the document was opened using Pdf.OpenDocumentBinary, this property returns an empty string.

OriginalPath As String (Read-only)

Returns this document's full original path if the document was opened using Pdf.OpenDocument. If this is a new document, or if the document was opened using Pdf.OpenDocumentBinary, this property returns an empty string.

OriginalVersion As String (Read-only)

Returns this document's original PDF version embedded in the document header (such as "1.3"). If this is a new document, this property returns an empty string.

Outline As PdfOutline (Read-only)

Returns the PdfOutline collection of PdfOutlineItem objects this document's outline structure. For more information, see Section 10.2 - Outlines.

OwnerPassword As Boolean (Read-only)

Returns True if this document is an existing one (i.e. opened via OpenDocument or OpenDocumentBinary), encrypted and has the owner password specified. Returns False in all other cases. For more information about owner passwords, see Section 8.1 - Overview of PDF Security.

OwnerPasswordUsed As Boolean (Read-only)

Returns True if this document is an existing one (i.e. opened via OpenDocument or OpenDocumentBinary), encrypted, and the owner password (as opposed to the user password) was used to open it. Returns False in all other cases.

This property is useful for permission flag enforcement. For more information about owner passwords, see Section 8.1 - Overview of PDF Security.


PageLayout As pdfPageLayout (Integer) (Read/Write)

Returns or specifies the page layout to be used when the document is opened. This property can be set to one of the four pdfPageLayout constants defined by the AspPDF component, or an integer value. Valid values are:
  • pdfSinglePage (1): display one page at a time.
  • pdfOneColumn (2): display the pages in one column.
  • pdfTwoColumnLeft (3): display the pages in two columns, with odd-numbered pages on the left.
  • pdfTwoColumnRight (4): display the pages in two columns, with odd-numbered pages on the right.
Usage (C#):

objDoc.PageLayout = pdfPageLayout.pdfOneColumn;


PageMode As pdfPageMode (Integer) (Read/Write)

Returns or specifies how the document should be displayed when opened. This property can be set to one of the four pdfPageMode constants defined by the AspPDF component, or an integer value. Valid values are:
  • pdfUseNone (1): neither document outline nor thumbnail images are visible.
  • pdfUseOutlines (2): document outlines are visible.
  • pdfUseThumbs (3): thumbnail images are visible.
  • pdfFullScreen (4): full-screen mode, with no menu bar, window controls or any other window visible.
Usage (C#):

objDoc.PageMode = pdfPageMode.pdfUseOutlines;


Pages As PdfPages (Read-only)

Returns the PdfPages collection of PdfPage objects representing pages in the document. PdfPages is used to access, add and remove individual pages.

Path As String (Read-only)

Returns the full path under which this document was saved via the Save method. If the document was saved using SaveToMemory or SaveHttp, this property returns an empty string.

Permissions As Long (Read/Write)

If this document is encrypted, returns permission flags associated with this document. If the document is not encrypted, returns 0.

For the detailed description of the PDF permission flags, see Section 8.1.2 - Permission Flags.


Producer As String (Read/Write)

Returns or specifies the document's producer (usually the name of the application that generated this PDF file). When a new document is created, AspPDF sets this property to "Persits Software AspPDF - www.persits.com" by default.

Subject As String (Read/Write)

Returns or specifies the document's subject.

Title As String (Read/Write)

Returns or specifies the document's title.

UserPassword As Boolean (Read-only)

Returns True if this document is an existing one (i.e. opened via OpenDocument or OpenDocumentBinary), encrypted and has the user password specified. Returns False in all other cases. For more information about user passwords, see Section 8.1 - Overview of PDF Security.

Version As String (Read/Write)

Specifies the PDF version to be embedded in the document header when the document is saved. "1.3" by default.

Methods

Sub AppendDocument (Document As PdfDocument)
Appends (stitches) an existing PDF document to the current one. Document must be an instance of the PdfDocument object created via OpenDocument or OpenDocumentBinary, but not CreateDocument. One or more documents can be stitched to this document by calling the AppendDocument method multiple times.

If Document is secure, it must have been opened with the owner password, not the user password, otherwise this method throws an error exception.

For more information on document stitching, see Section 12.2 - Document Stitching.


Sub Close ( )
Closes the underlying PDF file if this document object is based on an existing PDF, i.e. opened via the OpenDocument method. Has no effect if this is a new document.

A PDF file opened via OpenDocument always gets closed automatically when the corresponding PdfDocument object is destroyed. However, under .NET garbage collection, the actual object destruction may be deferred thus leaving the PDF file opened and locked indefinitely. The Close method enables you to close the file explicitly when your application needs it.


Function CreateAction (Param As Variant, Value As String) As PdfAction
Creates and returns an instance of the PdfAction object representing an action.

Param is a PdfParam object or parameter string specifying the action type and other type-specific parameters.

Value has different meanings depending on the action type and may be ignored altogether by some action types.

For the detailed description of the CreateAction method and its parameters, see Section 10.4 - Actions.


Function CreateDest (Page As PdfPage, Param As Variant) As PdfDest
Creates and returns an instance of the PdfDest object representing a destination. This method is redundant. It is recommended that the method Page.CreateDest be used instead.

Page is a PdfPage object the destination is associated with.

Param is a PdfParam object or parameter string specifying various parameters of the destination.

For the detailed description of the CreateDest method and its parameters, see Section 10.1 - Destinations.


Function CreateGraphics (Param As Variant) As PdfGraphics
Creates and returns an instance of the PdfGraphics object representing a graphics (referred to as a Form XObject by PDF specifications).

Param is a PdfParam object or parameter string specifying various creation parameters of the graphics, including:

For more information on graphics, see Section 5.3 - PdfGraphics Objects.


Function CreateTable (Param As Variant) As PdfTable
Creates and returns an instance of the PdfTable object representing a table.

Param is a PdfParam object or parameter string specifying various creation parameters of the table, including:

  • Width, Height (required) - the table's initial width and height.
  • Cols, Rows (optional) - the initial number of columns and rows in the table. The table is 1x1 by default.
  • CellSpacing (optional) - the table's cell spacing which is the width of a margin separating cells from each other and the outer border. Similar to HTML's CELLSPACING attribute of the <TABLE> tag. 0 by default.
  • CellPadding (optional) - the table's cell padding which is the width of a margin separating cell contents from the cell's borders. Similar to HTML's CELLPADDING attribute of the <TABLE> tag. 0 by default.
  • Border (optional) - the width of the outer border. 0 by default (which means no border).
  • CellBorder (optional) - the width of all cell borders. 1 by default.
  • BorderColor, CellBorderColor (optional) - the color of the outer border and cell border, respectively. Black by default.
  • BgColor, CellBgColor (optional) - the color of the table background and cell background, respectively. Transparent by default.

For more information on tables in general and the CreateTable method in particular, see Chapter 7 - Tables.


Sub Encrypt (Optional OwnerPwd, Optional UserPwd, Optional KeyLength, Optional Permissions)
Encrypts a document with a key of the specified length using the specified passwords, and embeds the specified permission flags into the encrypted document. This method cannot be called on an existing document.

OwnerPwd - the owner password. Optional, an empty string by default.

UserPwd - the user password. Optional, an empty string by default.

KeyLength - the key length, must be either 40 or 128. Optional, 40 by default.

Permissions - a combination of pdfPermissions flags. Optional, pdfFull by default.

For more information on PDF security and the Encrypt method, see Chapter 8 - Security.


Function ExtractPages (Param As Variant) As PdfDocument
Extracts one or several pages from an existing document. Returns an instance of the PdfDocument representing the new document.

Param is a PdfParam object or parameter string specifying 1-based indices of pages to be extracted via the parameters Page1, Page2, Page3, etc.

An instance of the PdfDocument object returned by this method cannot be used for anything other than saving.

Usage:

Set NewDoc = Doc.ExtractPages("Page1=2; Page2=6")

For more information, see Section 9.5 - Page Extraction.


Function ImportFromUrl (URL As String, Optional Param, Optional Username, Optional Password ) As String
WARNING: The implementation of the ImportFromUrl method is currently "a work in progress." Use at your own risk!

Your feedback and bug reports would be appreciated.

Opens an HTTP URL and converts the content of the page into PDF. Populates the current PdfDocument object with the result of the conversion. The current PdfDocument can either be an empty document created with CreateDocument, or an existing document opened via OpenDocument/OpenDocumentBinary.

Return value: if the Debug parameter (see below) is set to True, this method returns a log of non-fatal errors. Otherwise returns an empty string.

URL can be an http or https address, such as "http://www.server.com/path/file.asp", or a physical local path such as "c:\path\file.html".

For more information about this method, see Chapter 13 - HTML to PDF Conversion.

Param is a PdfParam object or parameter string specifying various conversion parameters (all of them optional), including:

  • PageWidth - page width, 612 (8.5") by default.
  • PageHeight - page height, 792 (11") by default.
  • LeftMargin, RightMargin, TopMargin, BottomMargin - page margins, 54 (0.75") by default.
  • Landscape - if set to True, the document's pages have landscape orientation. False (portrait orientation) by default.
  • CodePage - specifies the encoding of the page, similar to the View/Encoding option in a browser. This parameter, if specified, overrides the charset value specified via a <META http-equiv="Content-Type"> tag in the document's body. 1252 (US ASCII) by default.
  • StopAfter - specifies the number of pages in a resultant document after which the document creation will be aborted and an exception thrown. Used mostly for debugging purposes. 50 by default.
  • DrawBackground - if set to True, each page of the generated PDF document will display a background specified by the source HTML document's BGCOLOR or BACKGROUND attributes (or their CSS equivalents BACKGROUND-COLOR and BACKGROUND-IMAGE.) False by default, which means the background remains transparent/white regardless of the source HTML document's background settings.
  • StartPage - specifies the 1-based index of a page to begin rendering on. Applies to non-empty documents only. 1 by default.
  • Debug - if set to True, the method returns a log of non-fatal errors encountered during the HTML to PDF conversion process, such as invalid image URLs, unknown fonts, etc. False by default. This parameter should be used for debugging purposes only.

Username, Password specify authentication parameters in case the URL is protected with basic authentication. These arguments can also be used to pass the authentication cookie name (prefixed with the word "Cookie:") and cookie value when using .NET Forms authentication. This is described in detail in Section 13.2 - Authentication.

Usage:

Set Doc = Pdf.CreateDocument
Doc.ImportFromUrl "http://www.server.com/path/file.asp", "landscape=true"
Doc.Save "c:\path\doc.pdf"
Set Doc = Pdf.CreateDocument
LogString = Pdf.ImportFromUrl( "c:\path\doc.htm", "debug=true" )
Doc.Save "c:\path\doc.pdf"
Set Doc = Pdf.OpenDocument( "c:\path\template.pdf" )
Doc.ImportFromUrl "http://www.server.com/path/file.asp", "startpage=2"
Doc.Save "c:\path\doc.pdf"

Function OpenImage (Path As String, Param As Variant) As PdfImage
Opens an image from a disk file and returns an instance of the PdfImage object representing this image. Supported image formats are BMP, GIF, JPEG and TIFF. This method returns Nothing if the file being opened is a multi-image TIFF and the Index parameter exceeds the number of images in the file.

Path is a full file path to the image. Must be a physical path, not a URL.

Param is a PdfParam object or parameter string specifying optional image opening properties, including:

  • Invert (optional) - if set to True, inverts an image and displays it as a negative. This parameter is useful for displaying CMYK JPEGs. False by default.
  • Interpolate (optional) - if set to True, instructs a viewer application to perform image interpolation when rendering the image for better quality (but at the expense of performance). False by default.
  • Index (optional) - specifies the 1-based index of an image within a multi-image TIFF file. This parameter is only used when a TIFF file is being opened, and ignored by all other types of images. 1 by default.

For more information on images, see Section 5.1 - PdfImage Object.


Function OpenImageBinary (Blob As Variant, Param As Variant) As PdfImage
Opens an image from a memory array specified by Blob. Returns an instance of the PdfImage object representing this image. This method should be used if the image being opened resides in the database as a blob.

Param is a PdfParam object or parameter string specifying optional image opening properties. See OpenImage for details.

For more information on images, see Section 5.1 - PdfImage Object.


Function Save (Path As String, Optional Overwrite = True) As String
Saves the document to disk, returns the file name under which the document 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.

For example, if a document is being saved under the name proposal.pdf with the Overwrite argument set to False, and a file with the same name already exists in the destination folder, the Save method will try the filenames proposal(1).pdf, proposal(2).pdf, etc. until a unique name is found.

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

For more information, see Section 3.1 - Hello World Application.


Sub SaveHttp (DispHeader As String, Optional ContentType)
Sends the document to an HTTP stream. This method enables your Web-based application to send PDF documents directly to client browsers without having to save them to disk first. 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=filename.pdf"

or

"attachment; filename=filename.pdf"

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

ContentType specifies the value for the Content-Type header. By default, this value is "application/pdf". Using this argument is generally not recommended.

For more information on the SaveHttp method, see Section 3.2.2 - Saving to HTTP Stream.


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

For more information on the SaveToMemory method, see Section 3.2.1 - Saving to Memory.


Sub SetViewerPrefs ( Param As Variant )
Sets various viewer preferences for the document.

Param is a PdfParam object or parameter string containing various viewer preference parameters, including:

  • HideToolbar (optional) - if set to True, hides the viewer application's tool bar.
  • HideMenubar (optional) - if set to True, hides the viewer application's menu bar.
  • HideWindowUI (optional) - if set to True, hides user interface elements in the document's window (such as scroll bars and navigation controls).
  • FitWindow (optional) - if set to True, resizes the document's window to fit the size of the first displayed page.
  • CenterWindow (optional) - if set to True, positions the document's window in the center of the screen.
  • DisplayDocTitle (optional) - if set to True, makes the window's title bar display the document title taken from the Title property of the document. Otherwise, the title bar will display the name of the PDF file containing the document.
  • NonFullScreenPageMode (optional) - the document's page mode specifying how to display the document on exiting full-screen mode. Valid values are: 1 (use none), 2 (use outlines), and 3 (use thumbs).

Function Sign (Msg As Object, Name As String, Optional Reason, Optional Location, Optional Param) As PdfAnnot
Digitally signs the document, embeds the signature into the document in PKCS#7 certificate-based format. Returns an instance of the PdfAnnot object representing this signature field. Documents signed with this method can only be saved to disk, not to memory or an HTTP stream.

Msg is an initialized CryptoMessage object of the Persits Software AspEncrypt component.

Name specifies the signer name.

Reason specifies an optional reason for signing.

Location specifies an optional signing location.

Param is a PdfParam object or parameter string specifying various signature creation parameters, including:

For more information on the Sign method, see Section 8.3 - Digital Signing.

Function VerifySignature (Msg As Object) As PdfSignature
Verifies a PKCS#7 signature in the document. Can only be called on an existing document, and only on a file-based, not memory-based, document.

Returns Nothing if the document contains no PKCS#7 signatures. Otherwise, returns an instance of the PdfSignature object encapsulating various signature properties, including validation status, etc.

Msg is an empty CryptoMessage object of the Persits Software AspEncrypt component.

For more information on signature validation, see Section 8.3.4 - Signature Validation.


PdfFont PdfDest
Search AspPDF.com

  This site is owned and maintained by Persits Software, Inc. Copyright © 2003. All Rights Reserved.