PdfManager Object

Overview

PdfManager is AspPDF's central top-level object. It is creatable via CreateObject("Persits.Pdf") or the New operator. PdfManager serves as an "object factory" for other objects, most notably PdfDocument. It also provides formatting and registration key-related functionality.

Member List

Properties


Expires As Date (Read-only)
Returns the component's expiration date obtained from the registration key in use. If the returned value is 9/9/9999, it means the registration key is permanent.

Version As String (Read-only)
Returns the current component version in the format "X.X.X.X Build XXXX", for example "3.4.0.1 Build 13567".

RegKey As String (Write-only)
Specifies the registration key. If this property is not set, AspPDF will look for a registration key in the system registry under HKLM\Software\Persits Software\AspPDF\RegKey. If the key is invalid, this property will throw an error exception. AspPDF requires a registration key even for evaluation purposes. A free 30-day evaluation key can be obtained at www.asppdf.com.

Methods


Function CreateDocument(Optional ID) As PdfDocument

Creates an empty PDF document, returns an instance of the PdfDocument object representing this document.

ID is a binary number, specified as a hex string, to be used as this document's identifier. If this argument is omitted, AspPDF will generate a random 128-bit document identifier. Use this argument only if you need your document to have a specific identifier for accountability or other purposes. The current document identifier can be retrieved via PdfDocument's ID property.


Function CreateParam(Optional ParamStr) As PdfParam

Creates an instance of the PdfParam object optionally initialized with a parameter string specified by ParamStr. If the ParamStr argument is omitted, the method creates an empty PdfParam object.

For more information about the PdfParam object and parameter strings, see Section 2.3 - PdfParam Object.


Function FormatDate(Date As Date, Format As String) As String

This is an auxiliary method which returns a formatted string for a Date.

Format is a formatting string that contains one or more codes that represent various components of a date/time. The formatting codes are listed below (copied from MSDN):

%a
Abbreviated weekday name
%A
Full weekday name
%b
Abbreviated month name
%B
Full month name
%c
Date and time representation appropriate for locale
%d
Day of month as decimal number (01 - 31)
%H
Hour in 24-hour format (00 - 23)
%I
Hour in 12-hour format (01 - 12)
%j
Day of year as decimal number (001 - 366)
%m
Month as decimal number (01 - 12)
%M
Minute as decimal number (00 - 59)
%p
Current locale’s A.M./P.M. indicator for 12-hour clock
%S
Second as decimal number (00 - 59)
%U
Week of year as decimal number, with Sunday as first day of week (00 - 53)
%w
Weekday as decimal number (0 - 6; Sunday is 0)
%W
Week of year as decimal number, with Monday as first day of week (00 - 53)
%x
Date representation for current locale
%X
Time representation for current locale
%y
Year without century, as decimal number (00 - 99)
%Y
Year with century, as decimal number
%z
Time-zone name or abbreviation; no characters if time zone is unknown
%%
Percent sign

Usage:

str = Pdf.FormatDate( Now, "%d %b %Y") ' produces "17 Nov 2023"

Function FormatNumber(Number As Single, Optional Param) As String

An auxiliary method that returns a formatted string for a Number. Param is a PdfParam object or parameter string specifying various formatting parameters (all optional), including:

  • Precision - the number of decimals after the decimal point. 6 by default.
  • Delimiter - if set to True, thousands delimiters are inserted. False by default.
  • NoMinus - if set to True, uses parentheses for negative numbers instead of the minus sign. False by default.
  • European - if set to True, uses "," for the decimal point and "." for thousands separators. False by default.

Usage:

' Produces 1,234.57
str = Pdf.FormatNumber(1234.56789, "Precision=2, Delimiter=true")

' Produces 1.234,57
str = Pdf.FormatNumber(1234.56789, "Precision=2, Delimiter=true; European=true")

Function InjectTextIntoFile(Path As String, Text As String, Location As Integer) As String

An auxiliary method which places UTF-8 encoded Text into a file specified by Path at a location specified by Location. Returns the filename (without the path) of the file specified by Path.

Use this method to inject a digitial signature generated on a user workstation into a server-side PDF. This functionality is described in Section 8.4 - Client-Side Signing of Server-Side PDFs.

This method was introduced in Version 3.4.


Function LoadTextFromFile(Path As String) As String

An auxiliary method which loads a text string from a file specified by Path. A file can be in ANSI or Unicode (little endian or big endian) formats.

All text-handling method such as PdfCanvas.DrawText expect a text string to be passed as an argument. If the text to be drawn resides in a file, the LoadTextFromFile method can be used to load the file into a text string which can them be passed to a text-drawing method.


Sub LogonUser(Domain As String, Username As String, Password As String, Optional Flags = 2)

Impersonates the specified user account. If Domain is empty, the local computer will be used to validate the password. Use this function if your current security context does not allow you to perform a certain operation such as sending an image to the network printer.

Flags may be set to one of the following values: LOGON_INTERACTIVE (2, default), LOGON_NETWORK (3), LOGON_BATCH (4), and LOGON_SERVICE (5). Using this optional parameter is not recommended.

This method was introduced in Version 2.1.


Function OpenDocument(Path As String, Optional Password) As PdfDocument

Opens an existing PDF document from a file specified by Path. Password optionally specifies an owner or user password in case the document is password-protected.

Generally, the method returns an instance of the PdfDocument object representing the document being opened. If the document is password-protected and Password is missing, the method returns Nothing. If a password is required and an invalid one is specified, or if the file being opened is invalid or corrupt, the method throws an error exception.

For more information about working with existing documents, see Chapter 9 - Working with Existing PDFs.


Function OpenDocumentBinary(Blob As Variant, Optional Password) As PdfDocument

Same as OpenDocument, but opens an existing PDF from a memory array as opposed to disk file. This method is useful when the source document resides in a database table as a blob.

For more information about working with existing documents, see Chapter 9 - Working with Existing PDFs


Sub RunAsSystem()
Calls the Win32 API ::RevertToSelf to run the component under the system account's security context. This helps overcome certain permission problems when working with files and the system registry (such as obtaining font information from the registry when calling Fonts.Item) without having to tweak permissions. This method is only effective under ASP but not ASP.NET.

Sub SendBinary(Path As String, Optional ContentType, Optional DispHeader)

Sends an arbitrary file specified via Path from the server's hard drive to the client browser. This method can only be used under ASP and ASP.NET, but not VB or any other non-IIS environment. When used under ASP.NET, the classic ASP compatibility mode must be enabled, as follows:

<%@ Page aspCompat="True" other attributes %>

A script calling this method must not have any HTML tags in it (not even comments) as they would corrupt the HTTP stream.

ContentType optionally specifies the Content-Type header for the HTTP stream. This argument is "application/pdf" by default.

DispHeader optionally specifies the Content-Disposition header for the HTTP stream. By default, the header is set to "attachment; filename=filename.ext" based on the name of the file being sent. You may choose to pass a value for this argument if you want to specify a filename other than the actual document name.

Usage:

Pdf.SendBinary "c:\path\a.pdf", , "attachment; filename=b.pdf"