jsPDF
jsPDF copied to clipboard
Multi-page PDFs cause page errors in Adobe Reader, when created with .html()
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).
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.
I had the same problem @r3-gabriel did you find any solution?
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.
Same problem here, thanks for the workaround @r3-gabriel. Hope this gets fixed...
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.
Bump, still relevant.
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.
Bump, still relevant.
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.
@r3-gabriel wow, thank you for the workaround, you just saved my day.
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.
Bump, still relevant.
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.
Bump, still relevant.
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.
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.
Still relevant.
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;
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
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