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

Multi-page PDFs cause page errors in Adobe Reader, when created with .html() #3428

Open
r3-gabriel opened this issue May 31, 2022 · 24 comments

Comments

@r3-gabriel
Copy link

r3-gabriel commented May 31, 2022

I have read and understood the contribution guidelines.

When creating a PDF document via .html() with autoPaging enabled, Adobe Reader reports errors from the second page onward (jsPDF 2.5.1 / html2canvas 1.4.1).
adobe_error

The issue does not occur in PDF viewers in Chrome or Firefox. I´ve created a CodePen that reproduces this issue.

I also found a workaround: If I know the number of pages that the autoPaging will generate with .html(), I add those pages manually beforehand - this will result in a PDF file that works in Adobe Reader without issue. CodePen with workaround.

Because of this, I assume that autoPaging in .html() does not properly manage pages, which triggers the error.

@JasmeenTechnocomet
Copy link

I had the same problem @r3-gabriel did you find any solution?

@r3-gabriel
Copy link
Author

r3-gabriel commented Jul 23, 2022

I have not had more time to investigate - the descriped workaround worked good enough to address the issue in the short term.

To clarify how the workaround is implemented:

  • Create PDF normally with .html(), which results in the bug in Adobe Reader
  • Count the resulting pages
  • Throw away the created document
  • Create new, empty PDF
  • Add the expected number of pages manually with .addPage()
  • Add content with .html()
  • Now you have a valid PDF document

Because the workaround fixes the issue, I assume that .html() does not register pages correctly when more than 1 is generated.

@riquems
Copy link

riquems commented Sep 1, 2022

Same problem here, thanks for the workaround @r3-gabriel. Hope this gets fixed...

@github-actions
Copy link

github-actions bot commented Dec 1, 2022

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@r3-gabriel
Copy link
Author

Bump, still relevant.

@github-actions
Copy link

github-actions bot commented Mar 2, 2023

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@r3-gabriel
Copy link
Author

Bump, still relevant.

@ruanpetersen
Copy link

I am also rendering a multi-page PDF and am also experiencing this issue but due to images. When images are removed then the error goes away. I have tried multiple image formats.

@hansdoug
Copy link

@r3-gabriel wow, thank you for the workaround, you just saved my day.

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@r3-gabriel
Copy link
Author

Bump, still relevant.

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@r3-gabriel
Copy link
Author

Bump, still relevant.

@febkosq8
Copy link

Using "jspdf": "2.5.1"

I created a PDF with images and tables (AutoTable) and have the same issue.
I am creating all the required pages as I go.

As others mentioned, Chrome PDF viewer works fine but Adobe seems to hate the file.

Copy link

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@febkosq8
Copy link

Still relevant.

@dbyrzov
Copy link

dbyrzov commented Feb 19, 2024

Hello,

I had the same problem and was able to fix it by calling initially addPage and setPage and passing 0 to setPage.

const pdf = new jsPDF('p', 'px', [page.width, page.height]);
pdf.addPage();
pdf.setPage(page.pageNumber); // page.pageNumber is initially 0;

@febkosq8
Copy link

I had the same problem and was able to fix it by calling initially addPage and setPage and passing 0 to setPage.

const pdf = new jsPDF('p', 'px', [page.width, page.height]); pdf.addPage(); pdf.setPage(page.pageNumber); // page.pageNumber is initially 0;

Didn't work for me. I tried to change my code to the following but I still got the same error when I opened in Adobe Acrobat.

const doc = new jsPDF({
			orientation: "portrait",
			unit: "pt",
			format: "a4",
			putOnlyUsedFonts: true,
			floatPrecision: "smart",
		});
doc.addPage(); //new
doc.setPage(0); //new

@febkosq8
Copy link

febkosq8 commented May 4, 2024

I created a demo to show the issue with Adobe opening any pdf generated by jspdf.
Hopefully someone will be able to tell me where I am going wrong.

Current issues I am facing in Adobe Acrobat :

  • Page fails to load
  • Link to a page does not work

Copy link

github-actions bot commented Aug 3, 2024

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@febkosq8
Copy link

febkosq8 commented Aug 3, 2024

Still relevant.

Copy link

github-actions bot commented Nov 2, 2024

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@febkosq8
Copy link

febkosq8 commented Nov 2, 2024

Still relevant.

@vitappv
Copy link

vitappv commented Nov 12, 2024

I have the same problem. Still relevant.

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

No branches or pull requests

8 participants