-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support image compression in html() function #3178
Comments
Thanks for reporting this. Although I think this is more of a missing feature than a bug. If I read the documentation correctly, the |
Same issue. I have around 10 images in my html but very small sized PNGs. PDF size increases exponentially when converting my html to PDF. |
I disagree. If its intentionally not implemented, it should be spelled out in the documentation found at http:https://raw.githack.com/MrRio/jsPDF/master/docs/module-html.html Based on that, its not clear that certain properties are not applicable |
@ericjames Hey your method doesn't work for me.. images positions are not maintained. Y co-ordinates comes in negative |
I suppose the problem is that maybe images are stored in the resourcedictionary or html2canvas is drawing those images as bitmap? |
Hey i solved this problem, It's a hack but it does work very good What i did was just load the images with FAST compression but place them outside the boundary of the page. Now what happens is the cache automatically picks them so the original images comes compressed. So there will be duplicate copies of all the images but since they are not in the view it will not be shown and the one in the view will automatically will be compressed Use the same code as above just remove the line |
It can also be, that you by doing the img.remove() forced jsPDF to store the next identical image as a new resource. So then you would store the same image again and again. |
Using "null" for the "compression" parameter causes the function's logic to not detect it as "unset" and will not apply the default setting. resolves parallax#3178
After some digging it seem that this feature is actually in place but a bug in the usage of Line 845 in 30880b4
to do its job (to populate the "unset" compression variable) and the variable would move on with the invalid value of null .
With Cheers |
I have used this trick and was able to reduce the size of the pdf file generated by the save() method. However, since I need to send the generated pdf to the server, when I try to get the binary using output() method either as arraybuffer or blob - the resulting binary is still larger in size and the compression has no effect. Any directions will be appreciated! |
Filed Stackoverflow here: https://stackoverflow.com/questions/67753141/jspdf-html-method-doesnt-recognize-the-image-quality-option
Basically something is up with the jsPDF.html() method in which any img element blows up the file size. For me I have a 50kb image that blows up the PDF to 3.3mb with nothing else in it.
So I have to selectively replace those image elements with
onclone
.My workaround:
The text was updated successfully, but these errors were encountered: