Jump to content

Recommended Posts

Posted

This script utilizes the DynaPDF functions in MBS FileMaker Plugin for FileMaker to add an image into a PDF document. It initializes the DynaPDF library, imports an existing PDF, adds an image to the PDF, and saves the final version. Here’s a step-by-step breakdown of each action in the script.

 

1. Initializing DynaPDF

 

If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]

    Perform Script [ Specified: From list ; “InitDynaPDF” ; Parameter: ]

End If

 

This section checks if the DynaPDF library is initialized. The function MBS("DynaPDF.IsInitialized") returns 1 if DynaPDF is already initialized. If not, the script calls another script (InitDynaPDF) to perform the initialization. Initializing the DynaPDF library ensures that FileMaker can interact with PDF files and make modifications like importing, editing, and saving PDFs.

 

2. Creating a New PDF Document

 

Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ]

 

This line creates a new, empty PDF document. The MBS("DynaPDF.New") function is called to initialize the $pdf variable with a new PDF object that will hold the merged content. At this point, the PDF document is empty, awaiting the import of an existing PDF and an image insertion.

 

3. Importing the Current PDF

 

Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Merge PDFs::InputPDF) ]

Set Variable [ $r ; Value: MBS("DynaPDF.ImportPDFFile"; $pdf) ]

 

Here, the script imports an existing PDF file into the $pdf document:

  • MBS("DynaPDF.OpenPDFFromContainer"): This function opens the PDF from a container field (Merge PDFs::InputPDF) in the FileMaker database. This container field is expected to store the PDF that needs to be merged.
  • MBS("DynaPDF.ImportPDFFile"): After opening the existing PDF, this function imports the file into the new $pdf document created earlier.

Both actions ensure that the original PDF is now available in memory and ready for further manipulation. You can do a loop and import several PDF files if needed and import them one other the other to merge multiple documents.

 

4. Editing the PDF to Insert an Image

 

Set Variable [ $r ; Value: MBS("DynaPDF.EditPage"; $pdf; 1) ]

Set Variable [ $r ; Value: MBS("DynaPDF.SetPageCoords"; $pdf; "TopDown") ]

Set Variable [ $r ; Value: MBS("DynaPDF.InsertImage"; $pdf; Merge PDFs::Image; 100; 100; 200; 200) ]

Set Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ]

 

Now, the script moves on to inserting an image into the PDF:

  • MBS("DynaPDF.EditPage"): This function begins editing the first page of the PDF (1 refers to the first page). The script can add content like images or text here.
  • MBS("DynaPDF.SetPageCoords"): This function sets the coordinates for positioning content on the page. The "TopDown" option positions the content from the top-left corner of the page.
  • MBS("DynaPDF.InsertImage"): This is the key function for inserting the image. It places the image stored in the Merge PDFs::Image container field into the PDF at the specified coordinates (100, 100), with a width and height of 200 x 200 pixels.
  • MBS("DynaPDF.EndPage"): After editing, this function ends the editing session for the current page.

At this point, the image is inserted into the first page of the PDF document.

 

5. Saving the Merged PDF

 

Set Field [ Merge PDFs::FinalPDF ; MBS("DynaPDF.Save"; $pdf; "Merged.pdf") ]

 

This line saves the final PDF document, now containing both the original PDF content and the inserted image, to a file named Merged.pdf. The result is stored in the Merge PDFs::FinalPDF field. The file is saved to the default directory, or wherever the DynaPDF plugin has been configured to store the file.

 

6. Releasing the PDF Object

 

Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]

 

After saving the merged PDF, the script releases the $pdf object to free up memory. This is important for performance, especially when working with large PDFs or running the script multiple times. The MBS("DynaPDF.Release") function ensures that the memory used by the PDF document is properly cleaned up.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.