Create PDF
Creates an empty PDF file in memory. Add pages using script steps such as Append PDF, then close and save the file using the Close PDF script step.
See also
Options
-
Specify options displays the PDF Options dialog. When this option is selected,
Restoreindicates PDF options are stored in the script step.-
In the Document tab, you can specify descriptive information for the PDF file. For each of the options in the document tab, you can enter text directly, or click Specify to enter a field name or values from a calculation.
-
In the Security tab, you can assign passwords to the PDF file, as well as print and edit privileges. If print and edit privileges are allowed, you can specify if copying and screen reading software are permitted.
-
In the Initial View tab, you can define the initial view for the layout and magnification for the PDF file.
-
Compatibility
| Product | Supported |
| FileMaker Pro | Yes |
| FileMaker Go | Yes |
| FileMaker WebDirect | Yes |
| FileMaker Server | Yes |
| FileMaker Cloud | Yes |
| FileMaker Data API | Yes |
| Custom Web Publishing | Yes |
Originated in version
26.0
Description
This script step creates a new, empty PDF file in memory that you can then modify using other PDF file script steps. The PDF file is open and remains open until you close it with the Close PDF script step or Cancel PDF script step.
After a PDF file is open, you can:
-
Add content using the Append PDF script step
-
Add generated records using the Save Records as PDF script step with the "Currently open PDF" option
-
Save the final PDF using the Close PDF script step
This workflow is useful for creating complex PDF documents that combine pages from multiple sources, such as a cover page, report data, and appendices, all assembled into a single PDF file.
Notes
-
Only one PDF file can be open at a time. If a PDF file is already open, this script step returns error code 833 ("PDF file is already opened").
-
The created PDF file exists only in memory until you save it using the Close PDF script step.
-
The open PDF file and any unsaved changes are lost if either of the following happens:
-
The current FileMaker client session ends
-
The FileMaker Pro file whose script opened the PDF file closes without closing the open PDF file
-
Example 1 - Create a simple PDF document
Creates a PDF file, adds pages for the records currently being browsed, and saves it to the Documents folder.
Create PDF [ ]
Go to Layout [ "Contacts" (Contacts) ; Animation: None ]
Save Records as PDF [ Restore ; Save to: Currently open PDF ; Records being browsed ]
Set Variable [ $pdfFilePath ; Value: Get ( DocumentsPath ) & "Report.pdf" ]
Close PDF [ Save to: File ; $pdfFilePath ; Create folders: Off ]
Example 2 - Create a multi-section PDF report
Creates an encrypted PDF report by combining a cover page, multiple data sections, and a summary page. Create PDF uses Specify options to set a password to open the file.
Create PDF [ Restore ]
Append PDF [ Source: File ; "CoverPage.pdf" ]
Go to Layout [ "Orders" (Orders) ]
Save Records as PDF [ Restore ; Save to: Currently open PDF ; Records being browsed ]
Go to Layout [ "Customers" (Customers) ]
Save Records as PDF [ Restore ; Save to: Currently open PDF ; Records being browsed ]
Append PDF [ From: Source ; Global::SummaryPage ]
Set Variable [ $pdfFilePath ; Value: Get ( DocumentsPath ) & "Complete_Report_" & Year ( Get ( CurrentDate ) ) & ".pdf" ]
Close PDF [ Save to: File ; $pdfFilePath ; Create folders: Off ]
Example 3 - Create PDF with error handling
Creates a PDF report with error handling to ensure the PDF file is closed if an error occurs. Notice that after a failed attempt to modify the PDF file, the PDF file is closed without saving by the Cancel PDF script step.
Set Error Capture [ On ]
Create PDF [ ]
Set Variable [ $errorCode ; Value: Get ( LastError ) ]
If [ $errorCode ≠ 0 ]
Show Custom Dialog [ "Error" ; "Couldn't create PDF: " & $errorCode ]
Exit Script [ Text Result: "Failed" ]
End If
Append PDF [ From: File ; "CoverPage.pdf ]
Set Variable [ $errorCode ; Value: Get ( LastError ) ]
If [ $errorCode ≠ 0 ]
Cancel PDF
Show Custom Dialog [ "Error" ; "Could not add cover page: " & $errorCode ]
Exit Script [ Text Result: "Failed" ]
End If
Save Records as PDF [ Restore ; Save to: Currently open PDF ; Records being browsed ]
Set Variable [ $errorCode ; Value: Get(LastError) ]
If [ $errorCode ≠ 0 ]
Cancel PDF
Show Custom Dialog [ "Error" ; "Could not add records: " & $errorCode ]
Exit Script [ Text Result: "Failed" ]
End If
Close PDF [ Save to: File ; "Report.pdf" ; Create folders: Off ]
Set Variable [ $errorCode ; Value: Get ( LastError ) ]
If [ $errorCode = 0 ]
Show Custom Dialog [ "Success" ; "PDF created successfully" ]
Else
Show Custom Dialog [ "Error" ; "Could not save PDF: " & $errorCode ]
End If