« MBS FileMaker Plugin,… | Home | FileMaker Cloud with … »

Creating PDF/A in FileMaker with ZUGFeRD standard


Several FileMaker developers now use MBS FileMaker Plugin to create their invoices in ZUGFeRD standard. That's a data exchange format defined here in Germany, but other countries have similar formats. Basically we have a PDF in PDF/A 3b format and an embedded XML file. The PDF provides the visual and printable view of the invoice while the XML contains the same data readable for computers. 

With MBS Plugin and DynaPDF we can create such a ZUGFeRD PDF. We can either create a new file or import pages from existing PDFs. So even if you generate your invoices in FileMaker from layouts, you can convert them later. Here you see an example script for doing exactly this:

#Initialize DynaPDF if needed

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

Perform Script [“InitDynaPDF”]

End If

#Make new PDF environments

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

#Set import flags with Prepare For PDF/A enabled

Set Variable [$r; Value:MBS( "DynaPDF.SetImportFlags"; $pdf; "ImportAll¶ImportAsPage¶PrepareForPDFA" )]

#Load PDF from container

Set Variable [$r; Value:MBS("DynaPDF.OpenPDFFromContainer"; $pdf; ZUGFeRD Invoice::Invoice Template)]

#Import all pages

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

#PDF/A requires a language set

Set Variable [$r; Value:MBS("DynaPDF.SetLanguage"; $pdf; "en-US")]

#PDF/A requires a structure tree

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

#add xml with invoice data

Set Variable [$FileHandle; Value:MBS("DynaPDF.AttachFileText"; $pdf; ZUGFeRD Invoice::Invoice XML; "UTF-8"; "ZUGFeRD-invoice.xml"; "Invoice as XML")]

Set Variable [$r; Value:MBS("DynaPDF.AssociateEmbFile"; $pdf; "Catalog"; -1; "Alternative"; $FileHandle)]

#Check if this PDF conforms to PDF/A-3b

Set Variable [$c; Value:MBS("DynaPDF.CheckConformance"; $pdf; "ZUGFeRD Basic")]

If [$c = 1]

# A RGB ICC profile must be added to the document

Set Variable [$r; Value:MBS("DynaPDF.AddOutputIntentEx"; $pdf; ZUGFeRD Invoice::RGB ICC Profile)]

Else If [$c = 2]

# A CMYK ICC profile must be added to the document

Set Variable [$r; Value:MBS("DynaPDF.AddOutputIntentEx"; $pdf; ZUGFeRD Invoice::CMYK ICC Profile)]

Else If [$c = 3]

# A Gray, RGB, or CMYK ICC profile must be added to the document 

Set Variable [$r; Value:MBS("DynaPDF.AddOutputIntentEx"; $pdf; ZUGFeRD Invoice::RGB ICC Profile)]

End If

#save to container

Set Variable [$PDFData; Value:MBS("DynaPDF.Save"; $pdf; "invoice.pdf")]

Set Field [ZUGFeRD Invoice::Output PDF; $PDFData]

Commit Records/Requests []

#cleanup memory

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

As you see we first initialize DynaPDF if it's not already done. In a new PDF environment, we import from a container the whole PDF. Of course you can import from files or just import pages from different PDFs as needed to build in memory your final PDF. Than we define language and structure tree as required for PDF/A. We attach the XML from a field in this example. The XML is just a block of text which you can generate before, e.g. by filling values into a template.

Next we check conformance with ZUGFeRD standard. If you have DynaPDF Lite license, we only check and report okay or error. If you have a DynaPDF Pro + PDF/A license, we can fix errors and convert any PDF to PDF/A here (DynaPDF Editions). Next we add the required output intent ICC color profiles. Finally we save the PDF to a container.

Please do not hestiate to contact us with your questions. We also have the same examples for Xojo.

07 03 17 - 11:46
one comment

Sorry, forget my mail. Just click the script :-)
Kai Ranke - 14 06 17 - 11:14


  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.