A question we are frequently asked is how to generate PDFs on the server and find them in a FileMaker application, inserted into container fields.
We will try to answer this clearly and illustrate our point with an example file.
The process takes place in three steps:
1 – The client triggers the server-side script
The client-side script will perform two operations:
-
Commit the record where the server-side script will need to write (depending on the use case, your server script may create a new record rather than modify an existing one. In that case, this step is unnecessary).
-
Call the server-side script, which will generate the PDF and insert it into a container field. A script parameter is passed to ensure that the server script can retrieve the correct context (record(s), sort order, print layout, etc.).
2 – The server script retrieves the context
In the example file, it’s quite simple: it just needs to find a record, so the script basically performs a find based on the script parameter. Often, it is necessary to find a set of records, sort them, etc. Everything that a Snapshot Link would allow, but unfortunately, you can’t open a Snapshot Link on the server. Your script might, therefore, be a bit more complex than just performing a search (Often, using Go To Related Record is the best option for, say, find an invoice record and then go to the related invoice lines viewed as list)
3 – The server script generates the PDF and inserts it into a container
Next, a file path $path
is determined, and the PDF is saved.
Since the Insert File script step is not server-compatible, we convert this path into a URL using the function ConvertFromFileMakerPath($path; URLPath)
.
We could directly insert from the URL into the container field, but I always prefer an intermediate step that involves passing through a variable. The reason is how containers are displayed in the FileMaker Pro interface afterward. By using a variable and Set Field, we get more consistent results between macOS and Windows.
To insert a file into a variable using the Insert From URL script step, we need to specify a cURL option: --FM-return-container-variable
.
We can then insert from the URL into the $pdf
variable and set the container field with the contents of the variable.
Here is an example file to illustrate the concept. Account name: admin (no password)
Downlad demo file: Server-Side PDF