Browser-side PDF to PNG conversion
Setup
Configure the worker by adding this to your Webpack configuration:
// webpack.config.js
{
module: {
rules: [
{
test: /pdf\.worker\.js$/,
use: { loader: 'worker-loader', options: { inline: true } }
}
]
}
}
The inline
option is not strictly necessary per se but highly advised to play well with Cross-Origin Policy.
Usage
import pdfToPng from "pdf-to-png";
// [...]
const pngBlob = await pdfToPng(pdfBlob);
Take a Blob as its unique mandatory argument and returns another Blob.
Most of the time, the entry will be a very specific type of Blob, the File.
See here for a simple and self-contained implementation example (in a React context).
Caveats
Implicit dependency to Webpack at the moment, due to the way workers are handled.
Development
Release
yarn prepublish
git add lib/ && git commit -m "<version>"
git push origin master
git tag <version>
git push origin <version>
Process inspired by this comment.