PdfPig icon indicating copy to clipboard operation
PdfPig copied to clipboard

XFA form support

Open mgnslndh opened this issue 3 years ago • 4 comments

It would be awesome if this library would support reading XFA forms. Is this something that you have thought about adding or need help with?

mgnslndh avatar Nov 07 '20 16:11 mgnslndh

Any help is appreciated, but yeah, It has been discussed earlier #160 and #25

InusualZ avatar Nov 09 '20 10:11 InusualZ

I will take a stab at it. First step will be to retrieve the embedded XML for XPD/XFA. Beyond that I will probably need guidance in how the API should look like but I will look at PDFBox for reference. Do you have access to any related specifications?

mgnslndh avatar Nov 10 '20 07:11 mgnslndh

Hi @mgnslndh currently there's no support as @InusualZ says. Unfortunately I think XFA is still a proprietary Adobe internal specification that the few applications supporting it have to license so I don't know if there's any accessible specification.

As far as the PDF specification goes you need section 8.6.7 here https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdf_reference_archive/pdf_reference_1-7.pdf

Additionally because it's deprecated in the PDF 2.0 specification I'm not sure what the future support will look like.

As a starter the form dictionary would be accessed something like:

var xfaDictionary = (document.Structure.Catalog
    .CatalogDictionary
    .Data["AcroForm"] as DictionaryToken)?.Data["XFA"] as DictionaryToken;

But with the internal PdfPig types you'd need to use the various utility methods that actually follow indirect references TryGet<T>(this DictionaryToken dictionary, NameToken name, IPdfTokenScanner tokenScanner, out T token) where T : IToken. A good starting reference is the AcroFormFactory:

https://github.com/UglyToad/PdfPig/blob/master/src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs#L50

EliotJones avatar Nov 16 '20 20:11 EliotJones

Thanks for the direction! I've started implementing simple support. Will push PR for you to look at when I've come a bit further.

mgnslndh avatar Dec 01 '20 18:12 mgnslndh