PDF Attachments in FileMaker with DynaPDF

Did you know you can have attachments within a PDF document?

Yes, PDF documents can embed files, including other PDF documents. This allows to bundle various files with a PDF document just like attachments on emails. Or you can merge other PDF documents into a PDF and make them accessible via menu in Acrobat Reader or with buttons or clickable areas.

Let's start with loading an existing PDF from a container into the DynaPDF workspace:

# Clear current PDF document
Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ] 
# Load PDF from container
Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; PDF File::Input PDF) ] 
# import a page
Set Variable [ $r ; Value: MBS("DynaPDF.ImportPDFFile"; $pdf; 1) ] 

Once you have a PDF to start, you can start to attach containers with DynaPDF.AttachFileContainer function. You can include a comment optionally and whether to compress the content. If you have a file on disk, please use DynaPDF.AttachFile function and use DynaPDF.AttachFileText for text files passed in a text.

For our example we walk over records for a separate table and then add each file as attachment:

Go to Record/Request/Page [ First ]
Loop [ Flush: Always ]
	# 
	If [ not IsEmpty ( PDF Attachments::Attachment ) ] 
		Set Variable [ $r ; Value: MBS( "DynaPDF.AttachFileContainer"; $pdf; PDF Attachments::Attachment; PDF Attachments::Name ) ] 
	End If
	# 
	Go to Record/Request/Page [ Next ; Exit after last: On ]
End Loop

Now if you like to later extract embedded files, you can import the PDF and then query DynaPDF.GetEmbeddedFileCount function. Use a loop in FileMaker to call DynaPDF.GetEmbeddedFile function to query details for each of the embedded files like the name, size or description. Using DynaPDF.GetEmbeddedFileAsContainer function, you can directly get the content of that embedded file as container value, so you can assign it to a field.

Using the upcoming 14.1 plugin version we include a new function DynaPDF.CreateGoToEAction to create an action to go to such an embedded file. That meany you could show a PDF page with a list of buttons or table cells to click on. When clicked, the Adobe Reader would follow the action and open the embedded file. Great for an index page to open embedded PDF files.

Let's write a small script to edit a page to add a button with an action to open the embeded file:

# we can add a button to open first attachment
Set Variable [ $r ; Value: MBS( "DynaPDF.EditPage"; $PDF; 1) ] 
Set Variable [ $FirstFilename ; Value: MBS( "DynaPDF.GetEmbeddedFile"; $PDF; 0; "name") ] 
# we create an action to open an embedded file by name
Set Variable [ $Action ; Value: MBS( "DynaPDF.CreateGoToEAction"; $pdf; "Child"; ""; 0; $FirstFilename; ""; 1; 1 ) ] 
# we create a button to open that embedded file
Set Variable [ $button ; Value: MBS( "DynaPDF.CreateButton"; $pdf; "OpenAttachment"; "Open First Attachment"; -1; 100; 100; 100; 20 ) ] 
Set Variable [ $r ; Value: MBS( "DynaPDF.AddActionToObj"; $pdf; "Field"; "OnMouseUp"; $Action; $Button ) ] 
Set Variable [ $r ; Value: MBS( "DynaPDF.EndPage"; $PDF) ] 

Let us know if you have questions and try the functionality.

1 Like