jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

addImage produces an blur or too low quality image in the pdf

Open Balaji-Gopal opened this issue 10 years ago • 67 comments

I am using the latest version of jsPDF 1.2.61, While adding an image it adds an blur image even though the image is of high quality, if I the same base64 in on-line decoder it produces the perfect image as the original, but the base64 produces low quality when I use addImage functionality of jsPDF.

Snippet:

var doc = new jsPDF('landscape'); var Imagebase64=null; doc.setFontSize(20); doc.text(35, 25, "GoodYear"); var Imagebase64='data:image/jpeg;base64,/'; doc.addImage(imagePath, 'jpeg',0, 5, 210, 35); doc.save("mypdf.pdf");

Balaji-Gopal avatar May 25 '16 03:05 Balaji-Gopal

I'm seeing the same thing. I just migrated to 1.2.61 from 1.0.272 (I didn't change anything else in my code) and images and texts drawn on canvas get very blurred when it gets pushed to pdf. This seems different then my previous results.

Canvas in browser. tubenotcherissue_canvas

PDF extract. tubenotcher_pdf_test

The pixel mapping from canvas to pdf seems off a bit. Oh, and for reference: each of those top 'tick' marks is spaced exactly 1" from each other.

Don't get me wrong, this is an awesome product, and I'm more than grateful. I will say with this many open issues, I'm feeling mighty guilty for not pitching in and trying to close out an item or two. I will say I found this product pretty confusing on the code side.

And for reference, here's the actual site. Its something custom bike frame manufacturers or custom off-road hobbyists would use. http://dogfeatherdesign.com/ttn_js

zipzit avatar May 26 '16 04:05 zipzit

Same problem here when adding an image from a canvas. I can confirm that image quality looks good in 1.0.272, but is very poor in 1.2.61. I see the issue for both PNG and JPG.

banders avatar Jun 08 '16 18:06 banders

I'm too getting the same issue.

abureviewer3 avatar Jun 11 '16 07:06 abureviewer3

confirmed in 1.2.61, but only for PNG, JPEG quality is ok but with black background:

the png in 1.0.272 looks like: old version pn

the png in 1.2.61 looks like: new version pn

the jpeg in 1.2.61 looks like: new version jpeg

lvbeck avatar Jul 08 '16 15:07 lvbeck

Same issue here, good quality on 1.0.272 and average/low quality on 1.2.61, both JPG as PNG.

DaanGeurts avatar Jul 11 '16 12:07 DaanGeurts

in prerelease 1.1.135, the quality is ok

lvbeck avatar Jul 12 '16 12:07 lvbeck

Same issue on 1.2.61

eliassotodo avatar Jul 12 '16 21:07 eliassotodo

+1 Same issue for me

bmolaga-r7 avatar Jul 20 '16 13:07 bmolaga-r7

Use below code, it will help you in clearing blur image:

$scope.doc.internal.scaleFactor = 1.55;

bhavik4748 avatar Jul 20 '16 13:07 bhavik4748

@bhavik4748 tested with the line, the image quality is slightly improved, but still very poor(aliasing), can not be used in production.

png in 1.2.61

Anyway many thanks.

lvbeck avatar Jul 20 '16 14:07 lvbeck

same issue for me on 1.2.61 @bhavik4748 thanks that really helped, I've found it better to do doc.internal.scaleFactor = 1.33;

ido172 avatar Jul 20 '16 15:07 ido172

try scalefactor of 1.7 or 1.8, image will be small be would be more precise.

bhavik4748 avatar Jul 21 '16 15:07 bhavik4748

Still getting the same problem even after using the scaling line

ghost avatar Jul 29 '16 13:07 ghost

@Sketched360 ,

notice that you should set right mimetype for the images ("image/jpeg" , "image/png")

bmolaga-r7 avatar Jul 31 '16 05:07 bmolaga-r7

I debugged versions 1 and 2 side by side, and came to the conclusion that this is caused by an undocumented change to the jsPDFAPI.arrayBufferToBinaryString function (line 4267 in the jspdf.debug.js). In this function, the following lines have been added: if('TextDecoder' in window){ var decoder = new TextDecoder('ascii'); return decoder.decode(buffer); } Commenting these out and the correct way of rendering the PNG is restored. I'm not sure why it's in there, or why it causes this problem, but at least there's a workaround.

jalgithub avatar Aug 30 '16 15:08 jalgithub

@jalgithub Nice find. Thanks!

Didjeeh avatar Sep 21 '16 11:09 Didjeeh

@jalgithub thx. Work fine

JulienB37 avatar Oct 03 '16 08:10 JulienB37

@bhavik4748 where do I insert that line of code? in jspdf.debug.js or in my own code?

burtontanner avatar Oct 25 '16 18:10 burtontanner

@burtontanner Read my comment above to properly restore the old working.

jalgithub avatar Oct 25 '16 18:10 jalgithub

@jalgithub Those lines are commented out in the version of jspdf that I have and the final image is still blurry. I am just searching to see if there is anything else that I can do.

burtontanner avatar Oct 25 '16 18:10 burtontanner