node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

a simple pdf is 900KB, after adding custom fonts (calibri) it increase PDF size 10X.

Open krupalimakadiya opened this issue 3 years ago • 1 comments

when i embedded 'calibri' font in my PDF, Surprisely increase size of PDF 900KB to 3MB, i'dont know why it's happening if you have solution recommended here,

krupalimakadiya avatar Feb 10 '22 13:02 krupalimakadiya

After spending lots of time found :roll_eyes: fixes like compress PDF via ghost script using shell.

First npm install shelljs; // (^0.8.5)

then, `const shell = require('shelljs');

const uncompressed_inputFile = '../input.pdf'; // directory path with file name const compressed_outputFile = '../output.pdf' // directory path with file name

shell.exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.2 -dPDFSETTINGS=/prepress -dColorImageResolution=144 -dNOPAUSE -dQUIET -dBATCH -sPAPERSIZE=a4 -sOutputFile=${compressed_outputFile} ${uncompressed_inputFile}'); `

for more options of ghostscript : https://www.ghostscript.com/doc/current/VectorDevices.htm#PDF -> (7.4 PDF file output).

P.S: Using above code i reduced PDF size from 3.0MB to 731KB.

krupalimakadiya avatar Feb 18 '22 06:02 krupalimakadiya