Open PDF
Opens a PDF file. Add pages using script steps such as Append PDF, then close and save the file using the Close PDF script step.
See also
Options
-
From is how the PDF file's location is specified:
-
File specifies a PDF file path. When selected, the Source file option becomes available.
-
Source specifies a PDF file in a container field or variable. When selected, the Source option becomes available.
-
-
Source file defines a list of one or more paths and filenames for the PDF file when From is File. The script step searches the list and uses the first PDF file it successfully locates. Paths must use one of the
imagepath prefixes. See Creating file paths. -
Source specifies the container field or variable that stores the PDF file when From is Source.
-
Password is a text expression for the password required to open an encrypted PDF file. If the PDF file is not encrypted, this option is ignored.
Compatibility
| Product | Supported |
| FileMaker Pro | Yes |
| FileMaker Go | Yes |
| FileMaker WebDirect | Partial |
| FileMaker Server | Yes |
| FileMaker Cloud | Yes |
| FileMaker Data API | Yes |
| Custom Web Publishing | Yes |
Originated in version
26.0
Description
This script step opens an existing PDF file that you can then modify using other PDF file script steps. The PDF file remains open in memory 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 original PDF file isn't modified unless you save the changes to the same location using the Close PDF script step.
-
For encrypted PDF files, if the password is missing or incorrect, this script step returns error code 831 ("Invalid PDF password").
-
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
-
-
In FileMaker WebDirect, the From: File option isn't supported.
Example 1 - Open and modify an existing PDF file
Opens an existing PDF file in the current directory using a path and filename of image:ExistingReport.pdf, adds the current record, and saves the modified version to image:UpdatedReport.pdf.
Open PDF [ From: File ; Source file: "ExistingReport.pdf" ]
Save Records as PDF [ Restore ; Save to: Currently open PDF ; Current record ]
Close PDF [ Save to: File ; "UpdatedReport.pdf" ; Create folders: Off ]
Example 2 - Open encrypted PDF file with password
Opens a password-protected PDF file stored in a container field, appends the pages from another PDF file, and saves the result to a global variable with the filename UpdatedContract.pdf.
Go to Layout [ "Contracts" (Contracts) ; Animation: None ]
Open PDF [ From: Source ; Source: Contracts::ContractPDF ; Password: •••••••• ]
Append PDF [ From: File ; Source file: "Appendix.pdf" ]
Close PDF [ Save to: Target ; Target: $$modifiedPDF ; Filename: "UpdatedContract.pdf" ]
Example 3 - Open PDF file with error handling
Opens a PDF file, then handles errors using a calculation to map error codes to user-friendly messages and the Cancel PDF script step to close the open PDF without saving it.
Set Error Capture [ On ]
Go to Layout [ "Contracts" (Contracts) ; Animation: None ]
Set Variable [ $pdfFilePath ; Value: "image:Contract.pdf" ]
Open PDF [ From: File ; Source file: $pdfFilePath ; Password: •••••••• ]
Set Variable [ $errorCode ; Value: Get(LastError) ]
Set Variable [ $errorMessage ; Value:
Case (
$errorCode = 0 ; "" ;
$errorCode = 5 ; "File operations are not supported in FileMaker WebDirect. Use a container field or variable instead." ;
$errorCode = 830 ; "PDF file not found or has an invalid format." ;
$errorCode = 831 ; "Incorrect password for encrypted PDF file." ;
$errorCode = 832 ; "PDF file security settings prevent modification." ;
$errorCode = 833 ; "Another PDF file is already open. Close it first." ;
"Unknown error opening PDF: " & $errorCode
)
]
If [ $errorCode ≠ 0 ]
Cancel PDF
Show Custom Dialog [ "PDF Error" ; $errorMessage ]
Exit Script [ Text Result: "Failed" ]
End If
Append PDF [ From: Source ; Source: Contracts::ContractPDF ]
Close PDF [ Save to: File ; $pdfFilePath ]