PdfStartFromTemplate(NewFileName As String, TemplateName As String) As Integer

 

Creates a new pdf file, based on a pdf template

 

The pdf file is created within the application data temporary folder, a first page is appended

and the template pdf file gets inserted on this page as background.

 

 

Parameters:

 

Name

Type

Description

NewFileName

String

Name of new pdf file.

 

The name can be given with or without .pdf extension.

If the extension is lacking, it will be added.

 

If a pdf file of the same name already exists within the temporary folder, then a counter value will be added to the main name of the file, for example: testfile.pdf becomes testfile1.pdf

TemplateName

String

Name of a pdf file which serves as background for the first page of the new pdf file.

 

A template file typically contains your logo and any static information to appear in the final pdf file.

 

One must previously have imported the template pdf-file with Script Manager.

See menu Script -> New Templates Manager

 

Returns:

 

Type

Value

Description

Integer

1

OK, the pdf file exists and the template has been imported.

Integer

0

Not OK, the pdf file does not exist.

Integer

2

Not OK, the pdf file exists, but no template was imported.

Integer

-2

An unknown exception occured

 

Available in:

 

WindowMain

WindowLink

YES

YES

 

Used in:

 

XojoScript Name

GUID

Create Seminar Invoice With Slip As PDF

739DA58E-17EE-41CE-BB54-E7362CFE17D4

Create Seminar Invoice As PDF

2C3F7F29-A29A-4338-ACF5-51894B709DA5

 

Hint: You can find references to XojoScripts which make use of this function by sending the following SQL statement to the database:

Select id,GUID, ScriptName,ScriptCode from im_scripts where ScriptCode Like '%PdfStartFromTemplate%'

 

Example XojoScript:

 

// Import your own letterhead pdf file from menu

// Scripts -> New Template Manager

Dim templateName As String = "template_letter_A4_P2_RC.pdf"

 

If PdfStartFromTemplate("testfile.pdf",templateName) = 1 Then

 

// Point of origin is top-left

PdfSetPageCoordsTopDown

 

// Define variables for position

Dim x,y As Double

 

// Set output font and color

PdfSetFont("Arial","Regular",10.0)

Call PdfSetFillColor("&c00000000") // black textcolor

 

// write a location and current date

x = 400.0

y = 30.0

Call PdfWriteText(x,y,"Basel, " + GetDateLocalized)

 

y = 100.0

Call PdfSetTextRect(x,y,200.0,-1)  // -1 = not breaking to next page

Call PDFwriteFText("LEFT","Oliver Osswald" + eol + "Gruthweg 9" + eol + "4132 Muttenz")

 

// Finalize PDF

Call PdfCloseFile

 

// Optimize final pdf, as we have imported pdf from unknown source

Call PdfOptimize(0)

 

// Open pdf in default pdf viewer

Call Pdflaunch

 

End If