how to inflate (decompress) image from pdf using node.js?
There are many ways to store an image in a PDF, however at the most basic level there are embedment’s of native files via /DCTDecode
or a reference URI to their external image data streams (e.g. v:/Public/imagestream.jpg). To be avoided as a security issue, thus only used in closed systems as ./local file.
4 0 obj <>
stream
endstream
endobj
The Alternative basic method is using pixel bitmaps. As per this question, that use /FlateDecode compression. Since PDF’s cannot support natively embedded PNG or many other modern file formats, except a few JPEG or TIFF variants.
Unsupported native images types like PNG are converted on import into one or two compressed raw pixelmaps that have no metadata for re-formating on extraction.
The image stored in the pdf has no density and is only meta-physically (Based on speculative or abstract reasoning) described as bits times /Width/Height/Length(of compressed data).
To inflate you multiply colour bytes by height by width to get the extracted dimensions so in this case that is 3 x 1500 x 970 = 4365000 (4.2 MB) as a headless pixelmap which can then be saved as any file format you wish such as use with a PNG library.

A simpler method is to use any command line tool that has such code included and poppler pdfimages has several output formats so -all will try the best match.
The output in this case will be a compressed 570,505 bytes.png
Alternatively mutool extract will produce a more compressed output of 328,335 bytes.png
Other PDF PixMaps as PNG libraries are available.
Read more here: Source link
