-
-
Notifications
You must be signed in to change notification settings - Fork 819
Open
Labels
Description
What were you trying to do?
I am trying to catch an encrypted or PDF with JavaScript included.
How did you attempt to do it?
This is a debug piece of code, I was running:
import { PDFCatalog, PDFArray, PDFDict, PDFDocument, PDFName } from 'pdf-lib';
const file = fs.readFileSync("test/fixtures/script.pdf");
const doc = await PDFDocument.load(file);
const acroForm = doc.catalog.AcroForm();
function iterate(dict, level) {
if (dict instanceof PDFDict) {
for (const [key, value] of dict.entries()) {
console.log(" ".repeat(level) + "-> " + key, value);
iterate(value, level + 1);
}
}
if (dict instanceof PDFArray) {
for (const i = 0; i < dict.array.length; i++) {
const item = dict.lookup(i);
console.log(" ".repeat(level) + "-> " + item);
iterate(item, level + 1);
}
}
}
console.log(acroForm);
iterate(acroForm, 1);
What actually happened?
The first item of that array was parsed wrongly as "text"
-> <<
/A 103 0 R
/AP <<
/N 50 0 R
>>
/BS <<
/S /B
>>
/DA (/HeBo 10 Tf 0 g)
/F 4
/FT /Btn
/Ff 65536
/MK <<
/BC [ 0 0 1 ]
/BG [ 0.75293 ]
/CA (Make Text Lines -> List Entries)
>>
/P 49 0 R
/Rect [ 275.709 286.727 447.855 306.727 ]
/Subtype /Widget
/T (Button1)
/Type /Annot
>>
-> /A PDFRef {objectNumber: 103, generationNumber: 0, tag: '103 0 R'}
What did you expect to happen?
This is
the file opened in PDF debugger:
How can we reproduce the issue?
The Example is above.
Version
1.17.1
What environment are you running pdf-lib in?
Node
Checklist
- My report includes a Short, Self Contained, Correct (Compilable) Example.
- I have attached all PDFs, images, and other files needed to run my SSCCE.
Additional Notes
No response