Class
PDFDocument
Description
An object containing graphics and/or text that can be saved to a PDF file.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
callout As PDFCallout |
|||
chart As DesktopChart, x As Double, y As Double, width As Double = -1, height As Double = -1 |
|||
chart As MobileChart, x As Double, y As Double, width As Double = -1, height As Double = -1 |
|||
ParamArray controls() As PDFControl |
|||
controls() As PDFControl |
|||
file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer, description As String = "" |
|||
file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer, description As String = "" |
|||
file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer, description As String = "" |
|||
f 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 |
|||
line As PDFLine |
|||
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 |
|||
x As Integer, y As Integer, width As Integer, height as Integer, description As String = "", markupColor As Color = &cFFFF79, type As PDFAnnotation.MarkupTypes = PDFAnnotation.MarkupTypes.Highlight |
|||
shape As PDFShape |
|||
ParamArray entries() As PDFTOCEntry |
|||
entries() As PDFTOCEntry |
|||
✓ |
|||
value As JSONItem |
|||
value As PDFDocument.PageSizes |
|||
f As FolderItem |
|||
page As Integer |
|||
page As Integer, Assigns transition 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 |
TimesNewRoman |
Arial |
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.Language
Language As String
The primary language of the document. This value is used to assist various PDF standard features/behaviors such as pronunciation when reading PDF text aloud.
Acceptable values start with a two letter language code followed by a two letter country code. Example values are en-US and es-ES. A complete set of acceptable values can be found here.
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.Permissions
Permissions As PDFPermissions
Indicates what limitations (if any) the document has in terms of opening, printing, copying its contents and more.
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.AddCallout
AddCallout(callout As PDFCallout)
Adds the callout to the current page of the PDF document.
PDFDocument.AddChart
AddChart(chart As DesktopChart, x As Double, y As Double, width As Double = -1, height As Double = -1)
AddChart(chart As MobileChart, x As Double, y As Double, width As Double = -1, height As Double = -1)
Adds the chart to the current page of the PDF document at the coordinates and size specified.
PDFDocument.AddControl
AddControl(ParamArray controls() As PDFControl)
Adds the array of controls passed to the PDF document.
PDFDocument.AddControl
AddControl(controls() As PDFControl)
Adds the array of controls passed to the PDF document.
PDFDocument.AddEmbeddedFile
AddEmbeddedFile(file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer, description As String = "")
Embeds file into the current page of the PDF document and indicates a clickable region that, when clicked, opens the embedded document with the associated app.
Var d As New PDFDocument
Var g As Graphics = d.Graphics
Var f As FolderItem = FolderItem.ShowOpenFileDialog("")
Const kAttachedFileText As String = "Attached File"
g.DrawText(kAttachedFileText, 20 , 20)
If f <> Nil Then
d.AddEmbeddedFile(f, 20, 20, g.TextWidth(kAttachedFileText), g.TextHeight)
End If
PDFDocument.AddEmbeddedMovie
AddEmbeddedMovie(file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer, description As String = "")
Embeds the movie file (.mp4 format) to the current page of the PDF Document. The movie will play, when the user double-clicks the active icon on the page.
Warning
Due to a known issue in Adobe Acrobat on Windows, to properly play embedded movies, the graphics settings must be properly configured.
PDFDocument.AddEmbeddedSound
AddEmbeddedSound(file As FolderItem, x As Integer, y As Integer, width As Integer, height As Integer, description As String = "")
Embeds the sound file (AIFF, 2 Channels, 16 bits, 44.1) into the current page of the PDF document and describes an active area that when double-clicked, plays the sound.
Const kAttachedSound = "Some nice sound"
Var d As New PDFDocument
Var g As Graphics = d.Graphics
Var f As FolderItem = FolderItem.ShowOpenFileDialog("")
If f <> Nil Then
d.AddEmbeddedSound(f, 100, 20, g.TextWidth(kAttachedSound), g.TextHeight, kAttachedSound)
End If
PDFDocument.AddFonts
AddFonts(f 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.AddLine
AddLine(line As PDFLine)
Adds line to the current page of the PDF Document.
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(file As FolderItem, 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.AddMarkup
AddMarkup(x As Integer, y As Integer, width As Integer, height as Integer, description As String = "", markupColor As Color = &cFFFF79, type As PDFAnnotation.MarkupTypes = PDFAnnotation.MarkupTypes.Highlight)
Adds any of the predefined styles of markup to the text found below the active area (as described by the x, y, width and height values) on the current page of a PDFDocument instance. When double-clicked it opens a popup annotation window.
' This example highlights the text found below the active area of the added markup annotation.
Var d As New PDFDocument
Var g As Graphics = d.Graphics
Const kSampleText As String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent placerat nisi vitae erat pharetra, ac consequat dui facilisis. Pellentesque quis sem non velit dictum fringilla id nec odio. Maecenas ultricies mi sed mauris dignissim sagittis. Pellentesque quis diam ligula. Nunc eu velit in tortor rhoncus commodo. Fusce a mi urna. In semper ex et volutpat lobortis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Sed magna elit, lacinia vel leo a, egestas ornare est. Donec nec feugiat arcu."
g.DrawText(kSampleText, 20, 500, 400)
Var h As Double = g.TextHeight(kSampleText, 400)
d.AddMarkup(20, 500 - g.TextHeight, 400, h, "Annotation Description")
PDFDocument.AddShape
AddShape(shape As PDFShape)
Adds the shape to the current page of the PDF document.
PDFDocument.AddTable
AddTable(table As PDFTable, x As Double, y As Double)
Adds the table passed at the x and y coordinates passed.
PDFDocument.AddTOCEntry
AddTOCEntry(ParamArray entries() 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(f 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.
Warning
On Linux, PDFDocument requires the Pango library to be installed. While it is installed by default on most Linux distributions, if it's missing and you call a PDFDocument function, an exception will be raised.
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
Desktop, console, web and iOS project types on all supported operating systems.
See also
Object parent class; PDFTable, DesktopCanvas control; PrinterSetup class