question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting black images after adding 27 images through addHTML

See original GitHub issue

I using JS PDF v 1.3.3, with in angular2 project. I am generating pdf with addHTML function. Code works fine for 26 pages. onces it crosses 26 pages complete pdf is generted with black images. I am using below code to generate the pdf.

has any one faced this kind of issue?

 this.pdfDoc.addHTML(this.pages[index], 0, 0, this @.options, () => {
                let obj = this.getClientHeightWidth(index);
                this.pdfDoc.addPage(obj.clientWidth, obj.clientHeight);
                index++;
                this.addPage(index);
            });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Uzlopakcommented, Sep 9, 2017

tbh, I dont know the syntax of angularJS. But if your code is grabbing the whole html-site, than it could be the buffer overflow.

https://stackoverflow.com/questions/6081483/maximum-size-of-a-canvas-element Like I said… I guess it is a buffer overflow.

A4 are 595x 842 pixels. If we take chomes limit of 32,767 pixels than we have 38 pages to render.

It could be also the addImage-Problem. Go to the addImage Plugin and replace the jsPDFAPI.arrayBufferToBinaryString method by this code.

	/**
	 * Convert the Buffer to a Binary String
	 */
	jsPDFAPI.arrayBufferToBinaryString = function(buffer) {
		if (typeof(window.atob) === "function") {
			return atob(this.arrayBufferToBase64(buffer));
		} else {
			var data = (this.isArrayBuffer(buffer)) ? buffer : new Uint8Array(buffer);
			var chunkSizeForSlice = 0x5000;
			var binary_string = '';
			var slicesCount = Math.round(data.byteLength / chunkSizeForSlice);
			for (var i = 0; i < slicesCount; i++) {
				binary_string += String.fromCharCode.apply(null, data.slice(i*chunkSizeForSlice, i*chunkSizeForSlice+chunkSizeForSlice));
			}
			return binary_string;
		}
	};

And then check again

0reactions
AswarthaAcommented, Mar 13, 2018

@newdevsoft7 I had like 35 applications altogether and I was generating PDF pages for all of them together. Now I am generating one page at a time and clearing the DOM…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting black images after adding 27 images through addHTML
I using JS PDF v 1.3.3, with in angular2 project. I am generating pdf with addHTML function. Code works fine for 26 pages....
Read more >
jsPDF addHTML exporting low quality image to PDF
It looks like that many are still using pdf.addHTML() and have the same low quality issue. pdf.addHTML() is actually deprecated now.
Read more >
How To Create a Black and White Image - W3Schools
Use the CSS filter property to convert an image to black and white. Grayscale Example. Change the color of all images to black...
Read more >
Adding custom code to your site - Squarespace Help Center
Enhance your site's style and appearance using advanced coding skills. You can build a website on Squarespace without coding or design...
Read more >
How to change a black and white photo to COLOR in Photoshop
How to colorize a black and white photo in Photoshop. This Photoshop tutorial shows how to get a realistic color photo from a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found