Jspdf: fromHTML plugin incompatible with Adobe Acrobat Reader

Created on 27 Aug 2015  路  14Comments  路  Source: MrRio/jsPDF

Hi,

I know that the fromHTML plugin (viewable at /jsPDF-master/examples/basic.html) is still in beta, so I'm not expecting for it to be perfect. However, the second page of the PDF is consistently giving us this error message in Adobe Acrobat Reader:

An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem.

The <header> and <footer>, if they exist, are present on page 2 and onward, but everything else is blank. In other words, for Adobe Acrobat Reader on both Mac and PC, the first page of a fromHTML-generated-PDF renders correctly and the rest are white and empty.

This problem occurs when opening the repo demo PDF in Adobe Acrobat Reader, so I'm confident that the issue is greater than a simple inability on my end to implement it correctly. Importantly, all other PDF readers render the PDF just fine. It looks to be specific to Adobe's method of PDF syntax specifications. Any ideas what the problem might be, or when we can get this fixed? I LOVE jsPDF and if this bug didn't exist then we could use it on a fairly extensive project.

Thanks!

Most helpful comment

Wow, okay. I updated my version of jspdf.debug.js to set the penultimate argument to null. It looks like this:

this.pdf.internal.write("q", "BT 0 g", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), null, "Td");

That did the trick!!

Thanks so much @jutunen. You're clearly a subject matter expert at this PDF stuff. @MrRio hasn't built a demo of the fromHTML feature that's longer than 1 page, so he hasn't come across this issue yet in Adobe Acrobat Reader, but you've nailed a core but that will need to be fixed.

In the meanwhile I'm going to use this patched version for our purposes. It's functioning great.

All 14 comments

Tip: Try to open the document with GNU gv to get a more informative error message. Use "-infoAll" command line option.

Hi @jutunen, thanks for weighing in. I'm on a Mac and the documentation online for using GNU gv is sparse and cryptic. Do you have a clearly outlined resource for how to get this up and running?

As a faster alternative, it sounds like you already have GNU gv running on your machine, so here is a link to a sample PDF that was generated by the html2PDF plugin: http://dev.perfectioncoding.com/sample.pdf

Notice that this PDF is rendering just fine in Google Chrome (my default browser) but blowing up in Adobe Acrobat Reader. Very strange.

Sorry, hadn't read #572 before posting this. We can safely move the conversation there, I think.

It seems that your problem is not about unbalanced q/Q operators, so let's stay here.
When opening the 2nd page of your sample.pdf with GNU gv, these messages appear:
_Error reading a content stream. The page may be incomplete._
_File did not complete the page properly and may be damaged._

So how come we're seeing it render just fine in a browser? Any suggestions?

Google Chrome is just able to handle bad PDFs.

I think I know what is wrong in your sample.pdf. It is these lines:

_q BT 0 g 60.00 722.00 rgb(0, 0, 0) Td_

It is that rgb(0,0,0) assignment that just should not be there. The line should be like this:

_q BT 0 g 60.00 722.00 Td_

So how would we go about fixing this so it doesn't happen for future-generated ones?

http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf

PDF reference page 406 tells us that Td operator does not have any operand for color.

For some reason on this line the color operand is assigned:

_this.pdf.internal.write("q", "BT 0 g", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), style.color, "Td");_

You could try to remove the _style.color_ parameter.

Wow, okay. I updated my version of jspdf.debug.js to set the penultimate argument to null. It looks like this:

this.pdf.internal.write("q", "BT 0 g", this.pdf.internal.getCoordinateString(this.x), this.pdf.internal.getVerticalCoordinateString(this.y), null, "Td");

That did the trick!!

Thanks so much @jutunen. You're clearly a subject matter expert at this PDF stuff. @MrRio hasn't built a demo of the fromHTML feature that's longer than 1 page, so he hasn't come across this issue yet in Adobe Acrobat Reader, but you've nailed a core but that will need to be fixed.

In the meanwhile I'm going to use this patched version for our purposes. It's functioning great.

I'm glad that I could help. Thanks to Ghostscript, I was able to discover the defective line from the sample PDF.
http://ghostscript.com/

i can't able to view jspdf file in adobe Reader . anyone please give any suggestion.
In browser it Working fine

@jutunen fix suggestion works great for me.

@jutunen fix doesn't work for me.

I'm using 'html2pdf', in browser pdf seems working, but when I open pdf using Acrobat Reader DC (version 2015.023.20070), I'm getting this error: 'An error exists on this page. Acrobat may not display the page correctly'.
Below is Javascript code:
`function DownloadPDF() {
var panel = document.getElementById("<%=pnlContents.ClientID %>")
var pdf = new jsPDF('l', 'pt', 'letter');
var html = '' + panel.innerHTML + '';

    html2pdf(html, pdf, function (pdf) {
        pdf.save();
    });

    return false;

};
`

Below is html of #grPrintItems:

1

Thanks in advance..

jsFiddle: https://jsfiddle.net/ocwuzkt7/1/

This was solved with PR #1492

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MelanieCroce picture MelanieCroce  路  4Comments

BarathArivazhagan picture BarathArivazhagan  路  4Comments

yankeeBrit picture yankeeBrit  路  3Comments

mackersD picture mackersD  路  4Comments

sajesh1985 picture sajesh1985  路  5Comments