Hi, I try to parse a pdf but it never ends
const index = PDFObjectIndex.create();
const pdfParser = new PDFParser();
const parsedPdf = pdfParser.parse(data, index);
The pdf is this one : https://mle-sandbox.s3.amazonaws.com/bug7.pdf
For the moment I don't see where it's stuck
In fact it will ends but it takes much time. I have added some logs and most of time is spent in parsing numbers
@Hopding you told me you're working on performance improvements for pdf-lib. Do you think these improvements could improve parsing time for this file ?
Hello @mlecoq! I am indeed working on several performance improvements. The changes improve parsing times significantly for most PDF files. So I suspect it will help with the one your having trouble with.
I am unable to access the file via the link you shared. I get the following error when I tap on the link:
AccessDeniedAccess DeniedACFADBEE3B14786DV89MhuHrho0pR1NJX65rnSvf0V+ActBeUUE9CzLrXGlEqI9fYlPFxZ9q6refXwNxuHIDlGb70s8=
If you鈥檙e able to fix this, I can try it out with the new parser and let you know what I find.
Also, all the code for the rewrite is located here: https://github.com/Hopding/pdf-lib/tree/Rewrite. Feel free to try it out for yourself, if you want. I鈥檓 nearly finished now. I expect to cut a beta release no later than this weekend.
Ooops forgot to make the file public. You should have access now. I will try with the rewrite !
It takes around 8 minutes to be parsed with pdf-lib 0.6.3
I have changed my code a bit:
const start = new Date();
const pdf = fs.readFileSync(`${__dirname}/pdf/bug7.pdf`);
const pdfParser = new PDFParser(pdf);
pdfParser.parseDocument().then(parsedPdf => {
console.log(parsedPdf);
const end = new Date() - start;
console.log('Execution time: %dms', end);
});
Parsing is done within 413ms against 8min currently (impressive)
Out of curiosity, was the performance improvement due to the code change or update to pdf-lib or both?
@philipjmurphy The parsing speed improvement is due to the extensive rewrite I鈥檝e been working on in the Rewrite branch. The code sample that @mlecoq shared is using the new PDFParser from that branch.
I鈥檓 intending to release this rewrite as v1.0.0. As I mentioned, I plan to cut a beta release no later than this weekend. If you鈥檙e interested, I鈥檇 be happy if you鈥檇 help test it out!
Wow, those results are amazing. Sure, let me know if you'd like any particular test or I can use some of my own business PDFs with it.
fixed in 1.0.0-beta.1
Most helpful comment
I have changed my code a bit:
Parsing is done within 413ms against 8min currently (impressive)