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 and OpenDocument methods.

Properties Methods
Author
CompressedXRef
CreationDate
Creator
Encrypted
Filename
Fonts
Form
ID
ImportInfo
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
Save
SaveHttp
SaveToMemory
SetViewerPrefs
Sign
VerifySignature

Properties


String Author (Read/Write)

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

bool CompressedXRef (Read/Write)

Returns or specifies whether the current document uses a compressed cross-reference table. Modifying this property is generally not recommended.

DateTime CreationDate (Read/Write)

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

String Creator (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.

bool Encrypted (Read-only)

Returns True is the document is encrypted.

String Filename (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.

PdfFonts Fonts (Read-only)

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

PdfForm Form (Read-only)

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

String ID (Read-only)

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

PdfParam ImportInfo (Read-only)

Returns an instance of the PdfParam object populated with the Y-coordinate and page index of the lowest vertical boundary of HTML content rendered by the last successful call to ImportFromUrl. The item names are "Y" and "Page", respectively.

For more information, see Section 15.7 - Obtaining Y-Boundary.


int KeyLength (Read-only)

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

String Keywords (Read/Write)

Returns or specifies keywords associated with this document.

bool Mac (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.

String MetaData (Read/Write)

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

DateTime ModDate (Read/Write)

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

Object OpenAction (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:

objDoc.OpenAction = objDoc.Pages[1].CreateDest("Fit=true");

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


String OriginalFilename (Read-only)

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

String OriginalPath (Read-only)

Returns this document's full original path if the document was opened using PdfManager.OpenDocument. If this is a new document, or if the document was opened using PdfManager.OpenDocument( byte [] ), this property returns an empty string.

String OriginalVersion (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.

PdfOutline Outline (Read-only)

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

bool OwnerPassword (Read-only)

Returns True if this document is an existing one (i.e. opened via OpenDocument), 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.

bool OwnerPasswordUsed (Read-only)

Returns True if this document is an existing one (i.e. opened via OpenDocument), 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.


pdfPageLayout PageLayout (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.NET 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:

objDoc.PageLayout = pdfPageLayout.pdfOneColumn;


pdfPageMode PageMode (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.NET 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:

objDoc.PageMode = pdfPageMode.pdfUseOutlines;


PdfPages Pages (Read-only)

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

String Path (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.

int Permissions (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.


String Producer (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 for .NET - www.persits.com" by default.

String Subject (Read/Write)

Returns or specifies the document's subject.

String Title (Read/Write)

Returns or specifies the document's title.

bool UserPassword (Read-only)

Returns True if this document is an existing one (i.e. opened via OpenDocument), 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.

String Version (Read/Write)

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

Methods

void AppendDocument ( PdfDocument Document )
Appends (stitches) an existing PDF document to the current one. Document must be an instance of the PdfDocument object created via OpenDocument, 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.


void 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.


PdfAction CreateAction ( Object Param, String Value )
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.


PdfDest CreateDest ( PdfPage Page, Object Param )
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.


PdfGraphics CreateGraphics ( Object Param )
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.


PdfTable CreateTable ( Object Param )
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.


void Encrypt ( String OwnerPwd, String UserPwd )
void Encrypt ( String OwnerPwd, String UserPwd, int KeyLength )
void Encrypt ( String OwnerPwd, String UserPwd, int KeyLength, pdfPermissions 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. Can be an empty string.

UserPwd - the user password. Can be an empty string.

KeyLength - the key length, must be either 40 or 128. Assumed to be 40 if omitted.

Permissions - a combination of pdfPermissions flags. Assumed to be pdfPermissions.pdfFull if omitted.

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


PdfDocument ExtractPages ( Object Param )
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:

PdfDocument objNewDoc = objDoc.ExtractPages("Page1=2; Page2=6");

For more information, see Section 9.5 - Page Extraction.


String ImportFromUrl ( StringURL )
String ImportFromUrl ( StringURL, Optional Object Param )
String ImportFromUrl ( StringURL, Optional Object Param, String Username, String Password )
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.

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". It can also directly specify an HTML text string, such as "<html>some HTML code</html>".

For more information about this method, see Chapter 15 - 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.
  • Landscape - if set to True, the document's pages have landscape orientation. False (portrait orientation) by default.
  • LeftMargin, RightMargin, TopMargin, BottomMargin - page margins, 54 (0.75") by default.
  • LeftMarginNNN, RightMarginNNN, TopMarginNNN, BottomMarginNNN - page margins specified individually for page number NNN. Override the default margin settings. Pages with numbers higher than NNN inherit the new settings. The effective page width must be kept unchanged, i.e. the value PageWidth - LeftMarginNNN - RightMarginNNN (or in case of Landscape=true, PageHeight - TopMarginXXX - BottomMarginXXX) must be the same for all pages. These parameters were introduced by version 1.6.0.10.
  • 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, with an error message added to the log (see the Debug parameter below.) 200 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. If the specified value is greater than the number of pages in the current document, the rendering will begin on the last page of the document. 1 by default.
  • Hyperlinks - if set to True, all hyperlinks on the page being converted will be enabled (clickable). False by default. This parameter was introduced by version 1.7.
  • Media - specifies which cascading style sheets to read depending on their MEDIA attribute. Can be a combination (sum) of the following values: 1 ("all"), 2 ("screen"), 4 ("print"), 8 ("asppdf") and 128 (all others.) 255 by default, which means the MEDIA attribute is ignored altogether. This parameter was introduced by version 1.7.
  • Scale - specifies a scaling factor at which the document is rendered. 1 by default which means 100%. A number less than 1 shrinks the document, greater than 1 expands it. This parameter was introduced by version 1.7.
  • SplitImages - by default, if the bottom part of an image cannot fit on the page, the whole image is pushed down to the next page to preserve its integrity. If this parameter is set to True, an image may be split between adjacent pages if necessary. False by default. This parameter was introduced by version 1.7.
  • 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.
  • Timeout - if set to a positive number, specifies the timeout value (in seconds) for the Resolve, Connect, Send and Receive HTTP operations (same value for all four operations.) By default, these timeout values are 0 (infinite), 60 seconds, 30 seconds and 30 seconds, respectively. This parameter was introduced by version 1.7.

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 15.2 - Authentication.

Usage:

// Create a new PDF document from a URL, use Landscape mode, enable hyperlinks
PdfDocument objDoc = objPDF.CreateDocument();
objDoc.ImportFromUrl( "http://www.server.com", "landscape=true, hyperlinks=true" );
objDoc.Save( @"c:\path\doc.pdf" );


// Create a new PDF document from a local HTML file, enable logging
PdfDocument objDoc = objPDF.CreateDocument();
String LogString = objPDF.ImportFromUrl( "c:\path\doc.htm", "debug=true" );
objDoc.Save( @"c:\path\doc.pdf" );


// Render HTML from a URL onto an existing PDF document starting with page 2
PdfDocument objDoc = objPDF.OpenDocument( @"c:\path\template.pdf" );
objDoc.ImportFromUrl( "http://www.server.com/path/file.asp", "startpage=2" );
objDoc.Save( @"c:\path\doc.pdf" );


// Use direct HTML feed. The argument string must contain "<html>"
PdfDocument objDoc = objPDF.CreateDocument();
objDoc.ImportFromUrl( "<html><table><tr><td>...</td></tr></table>" );
objDoc.Save( @"c:\path\doc.pdf" );

PdfImage OpenImage ( String Path )
PdfImage OpenImage ( String Path, Object Param )
PdfImage OpenImage ( byte [ ] Blob )
PdfImage OpenImage ( byte [ ] Blob, Object Param )
Opens an image from a disk file or byte array, 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.

Blob is an array of bytes containing the image.

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.


String Save ( String Path )
String Save ( String Path, bool Overwrite )
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.


void SaveHttp ( String DispHeader )
void SaveHttp ( String DispHeader, String 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.NET environment as it internally uses ASP.NET's HttpContext.Current.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.


byte [ ] SaveToMemory ( )
Saves the document to a byte 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.


void SetViewerPrefs ( Object Param )
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).
  • PrintScaling (optional) - controls the page scaling option in a print dialog. True by default which means the application should use the current print scaling. If set to False, the print dialog should reflect no page scaling.

PdfAnnot Sign ( X509Certificate2 SignerCert, String Name, String Reason, String Location, Object Param )
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.

SignerCert is an instance of the X509Certificate2 object representing the ceriticate used for signing.

Name specifies the signer name.

Reason specifies a reason for signing, can be null.

Location specifies a signing location, can be null.

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.

PdfSignature VerifySignature ( ) 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 null if the document contains no PKCS#7 signatures. Otherwise, returns an instance of the PdfSignature object encapsulating various signature properties, including validation status, etc.

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


PdfFont PdfDest
Search AspPDF.net

Newsletter Signup

Other Products
AspPDF
AspUpload
AspJpeg
AspEmail
AspEncrypt
AspGrid
AspUser
  This site is owned and maintained by Persits Software, Inc. Copyright © 2003 - 2009. All Rights Reserved.