cross reference with Nan index values
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
That's indeed weird, can you please provide an example which generates a PDF in such a way?
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();
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.
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.").
I can provide examples of such PDF files if needed.
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;
#621 is most likely a duplicate.
Very interesting problem.
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