Decompressing PDF in pure javascript

60 Views Asked by At

I have pdfs with compressed data that qpdf decompresses and saves as a decompressed readable pdf. But I would like to make a node javascript-only solution that I can package up so my users don't have to install qpdf. There are a lot of javascript npm libraries, but none of them seem to have the same simple "open with uncompress and save" functionality of qpdf. Is this do-able with javascript only?

1

There are 1 best solutions below

0
user800268 On

Using the 'coherentpdf' libarary, I was able to lose the qpdf dependency and do it all in js. (The pdf files I'm working with all use Flate for compression.)

This is basically the node.js code:

let coherentPDF = require('coherentpdf');

let pdf = coherentPDF.fromFile('compressed.pdf', '');
coherentPDF.decompress(pdf);
coherentPDF.toFile(pdf, 'decompressed.pdf', false, false);