Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring parsing unreferenced objects #1641

Open
2 tasks done
rambo-panda opened this issue Jun 24, 2024 · 0 comments
Open
2 tasks done

Ignoring parsing unreferenced objects #1641

rambo-panda opened this issue Jun 24, 2024 · 0 comments

Comments

@rambo-panda
Copy link

What were you trying to do?

I want to get the number of pages in a PDF, but the count I am getting differs from what is shown in the PDF preview.

How did you attempt to do it?

var buf = await fetch("https://17zy-oto-export.oss-cn-beijing.aliyuncs.com/saaszy-2b589de8650eccdfddf32b8ec2c65fda/resource/record/production/2024/06/24/2021%E5%B0%8F%E5%AD%A6%E4%BA%8C%E5%B9%B4%E7%BA%A7%E6%9C%9F%E6%9C%AB%E8%AF%AD%E6%96%87%E6%B0%B4%E5%B9%B3%E6%B5%8B%E8%AF%95%E5%8D%B71_1719221446240425384.pdf").then(r => r.arrayBuffer());

var pdf = await require("pdf-lib").PDFDocument.load(buf);

console.log(pdf.getPageCount()); // 1    -- The actual count should be 2.

What actually happened?

I retrieved the page count of the PDF through the API as 1, but in reality, the actual number of pages is 2.

What did you expect to happen?

I hope to correctly return 2.

During the debugging process, I found that an unreferenced object was parsed, causing it to overwrite the correct Pages value.

Unreferenced object
Unreferenced object

Correct page information
WeChatWorkScreenshot_6eb0302a-fa1c-468f-ad46-0bc7cbff83a9

How can we reproduce the issue?

var buf = await fetch("https://17zy-oto-export.oss-cn-beijing.aliyuncs.com/saaszy-2b589de8650eccdfddf32b8ec2c65fda/resource/record/production/2024/06/24/2021%E5%B0%8F%E5%AD%A6%E4%BA%8C%E5%B9%B4%E7%BA%A7%E6%9C%9F%E6%9C%AB%E8%AF%AD%E6%96%87%E6%B0%B4%E5%B9%B3%E6%B5%8B%E8%AF%95%E5%8D%B71_1719221446240425384.pdf").then(r => r.arrayBuffer());

var pdf = await require("pdf-lib").PDFDocument.load(buf);

console.log(pdf.getPageCount());

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

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

No branches or pull requests

1 participant