How can I create a PDF file ...

This is a read only forum. It contains the most frequently asked questions about Amyuni products and licensing.
Post Reply
Dany
Amyuni Team
Posts: 113
Joined: Wed Sep 11 2002
Location: Montreal.
Contact:

How can I create a PDF file ...

Post by Dany »

and add watermarks to it using the Developer version of the PDF Creator?

Here is a sample VB function that would create a PDF file with 4 pages, add a watermark on each page and modify various font attributes and paper formats. In the sample, the PDF Creator control is assumed to be positioned on a VB form and named PDF1, it could also be created dynamically using the CreateObject VB function.

Dim nPages As Long, n As Long
Dim nObj As Long

nObj = 1
With PDF1
' set default font for whole document to avoid setting it for each object
.ObjectAttribute("Document", "DefaultFont") = "Courier New,6.5,400

For nPages = 1 To 4
.ObjectAttribute("Pages[" & nPages & "]", "Width") = 11 * 1440 ' 11 inches in Twips
.ObjectAttribute("Pages[" & nPages & "]", "Length") = 8 * 1440 ' 8 inches in Twips

' create diagonal watermark
.CreateObject acObjectTypeText, "Watermark" & nPages
.ObjectAttribute("Watermark" & nPages, "TextFont") = "Verdana,48,400,0"
.ObjectAttribute("Watermark" & nPages, "TextAngle") = -300 ' rotate watermark by 30 degrees

ObjectAttribute("Watermark" & nPages, "Text") = "T H I S I S A W A T E R M A R K"
.ObjectAttribute("Watermark" & nPages, "TextColor") = &HA0A0A0 ' light gray

' set a title for the page
.CreateObject acObjectTypeText, "Page " & nPages
.ObjectAttribute("Page " & nPages, "Text") = "This is Page " & nPages
.ObjectAttribute("Page " & nPages, "Top") = 720 ' 1/2 inch
.ObjectAttribute("Page " & nPages, "Left") = 1440 ' 1 inch
.ObjectAttribute("Page " & nPages, "Right") = 10 * 1440 ' 10 inches
.ObjectAttribute("Page " & nPages, "TextFont") = "Courier New,12,700,1,1" ' Bold, Italic and underlined

' create text lines
For n = 1 To 40
.CreateObject acObjectTypeText, "TextLine" & nObj
.ObjectAttribute("TextLine" & nObj, "Text") = "This is text line " & nObj
.ObjectAttribute("TextLine" & nObj, "Top") = 1440 + 144 * n
.ObjectAttribute("TextLine" & nObj, "Left") = 1440 ' 1 inch
.ObjectAttribute("TextLine" & nObj, "Right") = 10 * 1440 ' 10 inches
nObj = nObj + 1
Next

If nPages < 4 Then
.AddPage nPages ' create a new page
End If
Next

' refresh the display (in case we're viewing the file)
.CurrentPage = 1
.Refresh

' save the file
.Save "c:\temp\textlines.pdf", acFileSaveView
End With
Post Reply