jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

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

Open r3-gabriel opened this issue 2 years ago • 21 comments

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.

r3-gabriel avatar May 31 '22 08:05 r3-gabriel

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

JasmeenTechnocomet avatar Jul 23 '22 06:07 JasmeenTechnocomet

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.

r3-gabriel avatar Jul 23 '22 07:07 r3-gabriel

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

riquems avatar Sep 01 '22 22:09 riquems

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.

github-actions[bot] avatar Dec 01 '22 02:12 github-actions[bot]

Bump, still relevant.

r3-gabriel avatar Dec 01 '22 21:12 r3-gabriel

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.

github-actions[bot] avatar Mar 02 '23 02:03 github-actions[bot]

Bump, still relevant.

r3-gabriel avatar Mar 02 '23 19:03 r3-gabriel

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.

ruanpetersen avatar Mar 06 '23 06:03 ruanpetersen

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

hansdoug avatar Apr 13 '23 05:04 hansdoug

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.

github-actions[bot] avatar Jul 13 '23 02:07 github-actions[bot]

Bump, still relevant.

r3-gabriel avatar Jul 13 '23 05:07 r3-gabriel

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.

github-actions[bot] avatar Oct 13 '23 01:10 github-actions[bot]

Bump, still relevant.

r3-gabriel avatar Oct 13 '23 18:10 r3-gabriel

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.

febkosq8 avatar Nov 16 '23 22:11 febkosq8

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.

github-actions[bot] avatar Feb 15 '24 01:02 github-actions[bot]

Still relevant.

febkosq8 avatar Feb 15 '24 07:02 febkosq8

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;

dbyrzov avatar Feb 19 '24 13:02 dbyrzov

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 avatar Feb 19 '24 16:02 febkosq8

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

febkosq8 avatar May 04 '24 23:05 febkosq8