Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically reduce PDF Size in Node/Javascript

I have seen other solutions for other languages (Object C/Swift/ Java) and was wondering if there was an established method/package to reduce the size of PDF's using Node. Currently I use PDFKIT to generate PDFs in my backend but I need their file sizes to be about half (currently 1mb -> 500kb) or smaller ideally. I have looked through NPM and several forums but have not found a way to compress PDFs with javascript. I notice that countless Online-PDF-Compression websites exist and they are able to compress my 1mb PDF to 55kb. So I'm sure there are solutions that exist for Javascript/Node

like image 638
Joshua Wilkinson Avatar asked Jun 30 '26 01:06

Joshua Wilkinson


1 Answers

I faced a similar issue and after going through several forums, the solution I came up was to use shrinkpdf and to execute a shell command in node js I used shelljs library which has the following syntax,

const shell = require('shelljs')
shell.exec('./path_to_your_file')

All you have to do it execute the shell script given on the link.

like image 111
Dexter Avatar answered Jul 01 '26 14:07

Dexter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!