14 hours ago14 hr Today we like to make a certificate file in FileMaker with DynaPDF. And we have two ways to make this. First is a script to do the steps with Set Variable script steps. Second way is a Let() statement, where you make the PDF on the fly in a calculation. The script starts a new DynaPDF session and puts the number in $pdf variable. Then we open a template file from disk with DynaPDF.OpenPDFFromFile. You can of course change this to DynaPDF.OpenPDFFromContainer if you have the template in a container field. Then we import the whole file with DynaPDF.ImportPDFFile. Here you may also use DynaPDF.ImportPDFPage to import just one page. If you like, you can repeat this and import a second file by calling DynaPDF.OpenPDFFromFile or DynaPDF.OpenPDFFromContainer again to open another file and then import from that, too. You can always check with DynaPDF.GetPageCount how many pages you have and with DynaPDF.GetImportPageCount how many pages are in the currently open import PDF. After the imports, you can work on the PDF. Call functions like DynaPDF.Optimize to rebuild the PDF content and optionally shrink image resolution. Then we edit pages to add text. You may add page numbers, additional text, an URL to link to a webpage or like we do some text to fill the certificate. We load a fancy cursive font and place a date and names on the page. For this we use DynaPDF.WriteFTextEx where we define a rectangle and tell DynaPDF to center the text. Finally we close the page and save the PDF to a container value not the $PDFData variable. We later store that value into the container field to show it to the user. In a hosted solution we may use a global container field, which is basically a per-session variable. We we trigger this script via Data API, we store the PDF in a global container field and then with a second call on the same session with Data API, we can query the PDF and generate the PDF scripted on the FileMaker server in the Data API process without the user clicking. Here is the complete script: # Initialize DynaPDF if neededIf [ MBS("DynaPDF.IsInitialized") ≠ 1 ] Perform Script [ “InitDynaPDF” ; Specified: From list ; Parameter: ]End If# Clear current PDF documentSet Variable [ $pdf ; Value: MBS("DynaPDF.New") ]# Load templateSet Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromFile"; $pdf; "/Users/cs/Test/Template.pdf") ]# Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; WriteFText::Template) ]Set Variable [ $r ; Value: MBS("DynaPDF.ImportPDFFile"; $pdf; 1) ]# Edit page to add textSet Variable [ $r ; Value: MBS("DynaPDF.EditPage"; $pdf; 1) ]Set Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "SignPainter-HouseScript"; 0; 20) ]Set Variable [ $r ; Value: MBS("DynaPDF.WriteFTextEx"; $pdf; 144; 160; 170; 30; "Center"; Get(CurrentDate) ) ]Set Variable [ $r ; Value: MBS("DynaPDF.WriteFTextEx"; $pdf; 528; 160; 170; 30; "Center"; "Christian Schmitz" ) ]Set Variable [ $r ; Value: MBS("DynaPDF.WriteFTextEx"; $pdf; 132; 220; 576; 50; "Center"; "FileMaker AI Development" ) ]# and nameSet Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "SignPainter-HouseScript"; 0; 30) ]Set Variable [ $r ; Value: MBS("DynaPDF.WriteFTextEx"; $pdf; 132; 320; 576; 50; "Center"; "John Miller" ) ]# Close page and saveSet Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ]Set Variable [ $PDFData ; Value: MBS("DynaPDF.Save"; $pdf; "certificate.pdf") ]Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]# Put in ContainerSet Field [ WriteFText::PDF ; $PDFData ] If you like to copy this script, copy it to our converter first and then the XML in the script workspace. We may also include it in our examples. The same as the script can be done in a calculation. This allows you to make a calculated container field, where the PDF is created on the fly whenever the fields for the names change. Let([ // Clear current PDF document pdf = MBS("DynaPDF.New"); // Load template r = MBS("DynaPDF.OpenPDFFromFile"; pdf; "/Users/cs/Test/Template.pdf"); r = MBS("DynaPDF.ImportPDFFile"; pdf; 1); // Edit page to add text r = MBS("DynaPDF.EditPage"; pdf; 1); r = MBS("DynaPDF.SetFont"; pdf; "SignPainter-HouseScript"; 0; 20); r = MBS("DynaPDF.WriteFTextEx"; pdf; 144; 160; 170; 30; "Center"; Get(CurrentDate) ); r = MBS("DynaPDF.WriteFTextEx"; pdf; 528; 160; 170; 30; "Center"; "Christian Schmitz" ); r = MBS("DynaPDF.WriteFTextEx"; pdf; 132; 220; 576; 50; "Center"; "FileMaker AI Development" ); // and name r = MBS("DynaPDF.SetFont"; pdf; "SignPainter-HouseScript"; 0; 30); r = MBS("DynaPDF.WriteFTextEx"; pdf; 132; 320; 576; 50; "Center"; "John Miller" ); // Close page and save r = MBS("DynaPDF.EndPage"; pdf); PDFData = MBS("DynaPDF.Save"; pdf; "certificate.pdf"); r = MBS("DynaPDF.Release"; pdf)]; PDFData) Please try the script. We'll include it in the WriteFText.fmp12 file for the next version. You need a DynaPDF Lite license to do the merge. And of course a MBS Plugin license for seats in FileMaker Pro and/or for Server.
Create an account or sign in to comment