cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
107 stars 61 forks source link

reduce quality of pdf #25

Closed pablomaurer closed 7 years ago

pablomaurer commented 7 years ago

I use the it to generate the invoice as a pdf. But since my images are high quality the pdf gets with around 10 items a size of 20mb. So I need to find a way to reduce the overall quality of the pdf, or the quality of the images before they are added to the pdf.

May this can help

cesarvr commented 7 years ago

The objective of the plugin is to be WYSIWYG, you can control everything in the pre-render stage by scaling down the images, take a look at this, and then pass this to the pdf-generator.

pablomaurer commented 7 years ago

Before this plugin I used pdfmake and there I already did the js downscaling. But scaling 40 Hi-Res images down on an iPad-Air 2 took around 30 seconds and on some older iPhones even crash. I tried a lot solutions and you Plugin is the best so far, because it's native, fast and needs almost no memory. So I would like to keep going the native way.

WYSIGYG is a great objective, but if you provide an options to reduce the quality/filesize, it's still WYSIWYG. Now I will continue to try finding a way to add this to BNHtmlPdfKit and then to your plugin.

cesarvr commented 7 years ago

I think that if you try to do it in BNHtmlPdfKit will be more difficult because that API is using Webkit to transform all the HTML Document to PDF and in the process Webkit act just as a browser he get assets and renders it using some guidelines (HTML/CSS), when finish those assets add up to the total amount of your file (20mb), so If I was you i will try to attack those heavy assets (images) individually by compression/downscaling so the effort will be more effective.

pablomaurer commented 7 years ago

I already attacked the images with all power I had and the result was not satisfying =) So I will keep googling native solutions for today.

Solutions

Now I'm out of ideas. So closing this.

pablomaurer commented 7 years ago

Thank you anyway! =)