[Question] keys for PDFNames and PDFCatalog
See original GitHub issueHi - I have been referencing other closed issues which have been helpful such as https://github.com/Hopding/pdf-lib/issues/109
Hopding and others are getting objects out of the pdfDoc.index
with various getMaybe(key)
calls from the catalog
with keys such as 'AcroForm'
as in the below code from the above issue. Is there any documentation that explains what all of these keys are? Although I can see them in catalog.validKeys
, it feels like I’m arbitrarily pulling down these names, and I’m curious what they all do for me. For example, I’m following along with the code in the above issue, and the 'AcroForm'
doesn’t seem to give me all of the fields in my pdf, it only returns 6 fields as opposed to close to a hundred fields on the form.
const getAcroFields = pdfDoc => {
if (!pdfDoc.catalog.getMaybe('AcroForm')) return [];
const acroForm = pdfDoc.index.lookup(pdfDoc.catalog.get('AcroForm'));
if (!acroForm.getMaybe('Fields')) return [];
const acroFields = pdfDoc.index.lookup(acroForm.get('Fields'));
return acroFields.array.map(pdfDoc.index.lookup);
};
Similarly once a field is targeted say in an acroField
, is there documentation stating what all of the keys are for an acroField
? For a particular field I’m looking at, I see keys with names of ‘T’, ‘F’, ‘Subtype’, ‘DA’, ‘MK’ etc, and have no idea what they each represent.
Thank you. For reference, the form I have been looking at is attached if that helps.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
For future reference, the
pdfDoc.index.index.entries()
call can be replaced withpdfDoc.context.enumerateIndirectObjects()
.I did a bit of investigation into the PDF you shared. It turns out that:
I wrote a function to extract the text fields, and used it to populate each of them with their index number. Here’s the resulting document: filled_form_8949.pdf.
And here’s the script I used to create it:
I hope this helps. Please let me know if you have any further questions!