Class
PDFDocument
Description
An object containing graphics and/or text that can be saved to a file.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
ParamArray control As PDFControl |
|||
controls() As PDFControl |
|||
Folder As FolderItem |
✓ |
||
page As Integer, x As Integer, y As Integer, width As Integer, height As Integer, Optional x1 As Integer, Optional y1 As Integer |
|||
URL As String, x As Integer, y As Integer, width As Integer, height As Integer |
|||
file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer |
|||
ParamArray entry As PDFTOCEntry |
|||
entries() As PDFTOCEntry |
|||
✓ |
|||
value As JSONItem |
|||
value As PDFDocument.PageSizes |
|||
file As FolderItem |
|||
page As Integer |
|||
page As Integer, Assigns As PDFTransition |
Enumerations
PDFDocument.GraphicsMethods
GraphicsMethods
All the methods that are supported for creating graphics for PDFDocument. When creating templates via code, these help make the code more readable.
Name |
---|
Bold |
CharacterSpacing |
Clip |
DashPhase |
DrawLine |
DrawOval |
DrawPicture |
DrawPolygon |
DrawRectangle |
DrawRoundRectangle |
DrawText |
FillOval |
FillPolygon |
FillRectangle |
FillRoundRectangle |
FontName |
FontSize |
Italic |
LineCap |
LineDash |
LineJoin |
MatrixScaleX |
MatrixScaleY |
NextPage |
Outline |
PenColor |
PenSize |
ResetState |
RestoreState |
RotationAngle |
SaveState |
Translate |
Transparency |
Underline |
PDFDocument.PageSizes
PageSizes
Specifies the size of the PDF document page.
Name |
---|
Letter |
Legal |
Tabloid |
A4 |
A3 |
PDFDocument.StandardFontNames
StandardFontNames
The standard embedded fonts available.
Name |
---|
Times |
Helvetica |
Courier |
Symbol |
ZapfDingbats |
LiberationSans |
LiberationSansBold |
LiberationSansItalic |
LiberationSerif |
LiberationSerifBold |
LiberationSerifItalic |
LiberationMono |
LiberationMonoBold |
LiberationMonoItalic |
Property descriptions
PDFDocument.Author
Author As String
The name of the person who authored the document. This is stored in the document’s metadata to make it possible to find the document with search utilities.
PDFDocument.Compressed
Compressed As Boolean
If True, the document is stored compressed.
PDFDocument.Creator
Creator As String
The name of the application that created the document.
PDFDocument.CurrentPage
CurrentPage As Integer
The page which is accessed when using page-related properties and methods of the PDFDocument class.
PDFDocument.EmbeddedFonts
EmbeddedFonts As Boolean
If true, fonts used in the PDFDocument will be embedded in the created PDF file.
PDFDocument.Graphics
Graphics As PDFGraphics
An object that can be used to draw text and graphics into the document.
This property is read-only.
PDFDocument.Keywords
Keywords As String
The keywords that best indicate the contents of the document. This is stored in the document’s metadata to make it possible to find the document with search utilities.
PDFDocument.Landscape
Landscape As Boolean
If True, the document is in landscape orientation.
PDFDocument.PageCount
PageCount As Integer
The number of pages in the document.
This property is read-only.
PDFDocument.PageHeight
PageHeight As Double
The height (in points) of a page of the document.
PDFDocument.PageWidth
PageWidth As Double
The width (in points) of a page of the document.
PDFDocument.Subject
Subject As String
The subject of the document. This is stored in the document’s metadata to make it possible to find the document with search utilities.
PDFDocument.Title
Title As String
The title of the document. This is stored in the document’s metadata to make it possible to find the document with search utilities.
PDFDocument.ViewerOptions
ViewerOptions As PDFViewerOptions
Sets the UI elements the viewer should display when the document is to be displayed on the screen.
Method descriptions
PDFDocument.AddAnnotation
AddAnnotation(message As String, x As Integer, y As Integer)
Adds a widget to the current page at the coordinates passed that when clicked displays the message passed.
PDFDocument.AddControl
AddControl(ParamArray control As PDFControl)
Adds the array of control passed to the PDF document.
PDFDocument.AddControl
AddControl(controls() As PDFControl)
Adds the array of control passed to the PDF document.
PDFDocument.AddFonts
AddFonts(Folder As FolderItem)
All fonts within the folder and any subfolders are embedded within the document so that they are not required to be installed on the user’s machine in order for text that uses them to be rendered properly with those fonts.
This method is shared.
This example makes the fonts copied into the Resources > Fonts folder of the compiled app available to the PDFDocument created:
Var d As New PDFDocument
d.AddFonts(SpecialFolder.Resource("Fonts"))
PDFDocument.AddGotoPageArea
AddGotoPageArea(page As Integer, x As Integer, y As Integer, width As Integer, height As Integer, Optional x1 As Integer, Optional y1 As Integer)
Designates an area of the current page that will go to the page passed when pressed.
Providing the optional x1 and y1 parameters will ensure that the area of the page to which the user goes is visible.
PDFDocument.AddLinkArea
AddLinkArea(URL As String, x As Integer, y As Integer, width As Integer, height As Integer)
Designates an area of the current page that will go to the URL passed when pressed.
PDFDocument.AddLinkToPDFArea
AddLinkToPDFArea(URL As String, x As Integer, y As Integer, width As Integer, height As Integer)
Designates an area of the current page that will open the PDF file passed when pressed.
PDFDocument.AddTOCEntry
AddTOCEntry(ParamArray entry As PDFTOCEntry)
Creates a table of contents from the array of PDFTOCEntrys passed.
PDFDocument.AddTOCEntry
AddTOCEntry(entries() As PDFTOCEntry)
Creates a table of contents from the array of PDFTOCEntrys passed.
PDFDocument.ClearCache
ClearCache
Clears (deletes) all files created in the temporary folder as a result of various font operations.
PDFDocument.Constructor
Constructor(value As JSONItem)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a PDFDocument based upon the JSON data passed.
PDFDocument.Constructor
Constructor(value As PDFDocument.PageSizes)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a PDFDocument where the page size is based on the PageSize passed.
PDFDocument.Constructor
Constructor(width As Double, height As Double)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a PDFDocument where the page size is based width and height passed.
PDFDocument.Save
Save(file As FolderItem)
Creates the PDF document and saves the graphics and metadata to it.
PDFDocument.Template
Template As JSONItem
Returns a JSONItem that represents the PDFDocument in JSON format.
This JSON data can be passed into the PDFDocument constructor to create a PDFDocument effectively making this data act as a template.
PDFDocument.ToData
ToData As MemoryBlock
Returns a MemoryBlock that represents the PDFDocument’s contents.
PDFDocument.TransitionAt
TransitionAt(page As Integer) As PDFTransition
Gets the PDFTransition for the page passed.
TransitionAt(page As Integer, Assigns transition As PDFTransition)
Sets a PDFTransition for the page passed.
Transitions can be applied to a PDFDocument page to be used by the viewer app when enabled in presentation or slide show modes.
Notes
PDFDocument supports only .ttf and .otf font files.
Drawing
Every new object is drawn above the previous one in the same way as the Graphics class does in all other cases.
Meta data
The Author, Keywords, Subject and Title are metadata values that can be used by search utilities to find the document.
JSON format
PDFDocuments can be created by passing JSON data to the Constructor (see Constructors above). The JSON format required is as follows:
{
"General": {
"Author": String,
"Creator": String,
"Keywords": String,
"Subject": String,
"Title": String
},
"Document": {
"Compression": Boolean,
"EmbeddedFonts": Boolean,
"Landscape": Boolean,
"Width": Double,
"Height": Double
},
"Actions": { Dictionary { Dictionary } }
"Images": { Dictionary { Dictionary } }
Actions
Actions is a Dictionary of dictionaries, each containing a single graphics command and parameters you wish to invoke. For example:
"Actions": {
"0": {
"Color": "&h00FFFFFF"
},
"1": {
"FillRectangle": ".00,.00,612.00,792.00"
},
"2": {
"FontName": "Helvetica"
},
"3": {
"DrawText": "Sample text,_ENDTEXT_,100,200,200,False"
}
}
Images
Images is a Dictionary of dictionaries, each containing a single Base64-encoded image from the document (when generated but the Template method) regardless of how many times that image appears in the document. For example:
"Images":{
"0":
{"0":"\/9j\/4AAQSkZJRgABAQAASABIAAD………"},
"1":
{"1":"\/9j\/4AAQSkZJRgABAQAASABIAAD………"},
"2":
{"2":"\/9j\/4AAQSkZJRgABAQAASABIAAD………"}
}
Note that if you are planning to create this manually, the inner key must match the outer key.
Drawing text
The _ENDTEXT_ marker delimits the end of the text to be drawn from the rest of the parameters. This simplifies the JSON structure when created manually.
You can also save your PDFDocument JSON data for use later as a template, by calling the Template method.
Sample code
This example creates a PDFDocument object then draws a bar chart into and saves it to a file on the desktop:
Var pdf As New PDFDocument
Var g As Graphics = pdf.Graphics
g.PenSize = 1
g.DrawLine(0, 0, 0, 324)
g.DrawLine(0, 324, g.Width, 324)
Var r As New Random
Var startX As Integer = 1
Var colors() As Color
Var bars() As Integer
If colors.LastRowIndex = -1 Then
For n As Integer = 0 To 5
colors.Add(Color.RGB(r.InRange(0, 255), r.InRange(0, 255), r.InRange(0, 255)))
bars.Add(r.InRange(325 * 0.1, 325 - 325 * 0.2))
Next
End If
Var barWidth As Integer = g.Width / 6 * 0.8
Var spaceBetween As Integer = g.Width / 6 * 0.2
For n As Integer = 0 To 5
g.DrawingColor = colors(n)
g.FillRectangle(startX, 325 - bars(n), barWidth, bars(n) - 1)
startX = startX + barWidth + spaceBetween
Next
Var f As FolderItem = SpecialFolder.Desktop.Child("Barchart.pdf")
pdf.Save(f)
Compatibility
All projects types on all supported operating systems.
See also
Object parent class; DesktopCanvas control; PrinterSetup class