jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

cross reference with Nan index values

Open pascalPimaia opened this issue 12 years ago • 9 comments

I observed the content of generated files on window 7 with chrome here is the kind of xref I found at the end of the file

xref 0 20 0000000000 65535 f 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n 0000000NaN 00000 n trailer << /Size 20 /Root 19 0 R /Info 18 0 R

startxref NaN

pascalPimaia avatar Mar 12 '14 09:03 pascalPimaia

That's indeed weird, can you please provide an example which generates a PDF in such a way?

diegocr avatar Mar 28 '14 01:03 diegocr

Same thing happening for me in Windows 7 Chrome v.37. Here's my code:

var doc = new jsPDF('p', 'pt', 'letter');
doc.rect(20, 20, 10, 10);
doc.output();

dganoff avatar Sep 16 '14 20:09 dganoff

Hi dganoff. Thanks, but unfortunately that's too short code and unlikely to cause the problem by itself i'd say, because otherwise our live demos would have the same problem.

I think providing jsfiddle could be of great help here to reproduce the problem.

diegocr avatar Sep 16 '14 21:09 diegocr

I think that I have the same problem. jsPDF is used to generate one-page document which is then required to be saved by the user.

If the generated pdf is converted to blob and opened in Chrome, it is displayed correctly.

var blob = doc.output("blob");
var url = URL.createObjectURL(blob)

Using Chrome's controls to save the doc generates different content at the end of the file (most likely xref) than when saving the same document using jsPDF save() function.

The former can be opened in Chrome 38, but the latter can't be ("Failed to load PDF document.").

matejk avatar Nov 05 '14 08:11 matejk

I can provide examples of such PDF files if needed.

matejk avatar Nov 05 '14 08:11 matejk

I ran into this problem and was able to correct it by modifying the out method of jsPDF. Here is the function at the time of this writing:

out = function(string) {
    if (outToPages) {
        /* set by beginPage */
        pages[currentPage].push(string);
    } else {
        // +1 for '\n' that will be used to join 'content'
        content_length += string.length + 1;
        content.push(string);
    }
}

Notice that content_length is determined by calling string.length. However, in my case string was actually a number and needed to be converted to a string before using its length property.

content_length += string.toString().length + 1;

thomashigginbotham avatar May 05 '15 12:05 thomashigginbotham

#621 is most likely a duplicate.

matejk avatar May 05 '16 12:05 matejk

Very interesting problem.

Uzlopak avatar Feb 17 '18 02:02 Uzlopak

Thanks to @thomashigginbotham . I took your analysis and your recommendated change and modifiied it to a general parameter sanitization in the out-method.

Is fixed by PR #1620, will be part of the next release

Uzlopak avatar Feb 18 '18 14:02 Uzlopak