Skip to content

Add /AFRelationship and /Subtype to embedded files#5

Open
jenskutilek wants to merge 5 commits into
invopop:mainfrom
jenskutilek:main
Open

Add /AFRelationship and /Subtype to embedded files#5
jenskutilek wants to merge 5 commits into
invopop:mainfrom
jenskutilek:main

Conversation

@jenskutilek
Copy link
Copy Markdown

I'm working towards adding XML attachments with electronic invoices to PDFs in my rails app.

Trying to validate the generated PDFs, I found out I needed two things:

  • The /AFRelationship entry describing the relationship of the attachment to the PDF (/Alternative, /Data, /Source, /Supplement, /Unspecified)
  • The MIME type of the attachment, via the entry /Subtype, e.g. /text#2Fxml (representation of text/xml; default is application/octet-stream)

I just added those to the options:

attach "factur-x.xml", File.open("./factur-x.xml"),
               {
                 description: "Factur-X/ZUGFeRD-Rechnung",
                 relationship: :Alternative,
                 mime_type: "text/xml",
               }

The mime_type string is automatically converted to a symbol.

@jenskutilek
Copy link
Copy Markdown
Author

There are more things missing to make the resulting files PDF/A-3 compliant.

PDF/A-3 requires the /AF entry for all embedded files. I've not yet looked into how to add that.

https://www.loc.gov/preservation/digital/formats/fdd/fdd000360.shtml:

Relationship links are established from the document or parts of the document by use of the AF key, which contains an array of file specification dictionaries (as described above). Files associated with the entire document are represented by an AF key in the Catalog for the PDF file.

Also, there needs to be some specific metadata in PDF/A-3 files.

But this PR is a first step with two additions that seem useful to have in any case.

@timokleemann
Copy link
Copy Markdown

@jenskutilek, have you managed to achieve PDF/A-3 compatibility? I am still struggling...

Attaching the XML to the PDF works like a charm. But converting the PDF into a PDF/A-3 file has so far proved difficult...

@jenskutilek
Copy link
Copy Markdown
Author

@timokleemann, no, I didn't manage to solve this.

@krisdigital
Copy link
Copy Markdown

Hi @samlown 👋,

I extended this PR with the rest of the changes to make the embedding PDF/A-3 compliant:

jenskutilek#1

The only thing missing was creating the AF list entry that connects the files to the document. As far as I understand that is needed for every PDF/A-3. If you think it is out of scope for this gem just let me know 😎 Otherwise maybe we can get this merged and released, it is quite useful for complying with current German and French invoicing standards (Zugferd 🐴 and factur-x)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants