pdf2canvas
Convert a pdf to image dataURL / file
Installation
$ npm install pdf2canvas
Initialize
Example
const Pdf2Canvas = ; const pdfCanvas = './test.pdf';
API
.downloadPNG (options)
- Convert a pdf to PNG file(s) asynchronously
options
: {Object}pageRange
: {Array{number}}- the start page number and the last page number
- default to
[1, Infinity]
outputDir
: {string}- the specified directory to save image files
- default to
./
viewportScale
: {number} | {Function}- the viewport scale
- in case of a function is specified, the original width & height will be passed in as its arguments
- default to
1.5
config
: {Object}- PNG encode config
compressionLevel
: ZLIB compression level (between 0 and 9), default to 6filters
: the compression filter(s), default toPNG-ALL-FILTERS
palette
: the palette (indexed PNGs only), default to undefinedbackgroundIndex
: the background palette index (indexed PNGs only), default to 0resolution
: the resolution in pixels per meter (ppi), default to undefined
- Returns: {Promise} containing the saved file paths {Array{string}}
const result = await pdfCanvas;// => ["images/page-1.png", "images/page-2.png"]
.downloadJPEG (options)
- Convert a pdf to JPEG file(s) asynchronously
options
: {Object}pageRange
: {Array{number}}- the start page number and the last page number
- default to
[1, Infinity]
outputDir
: {string}- the specified directory to save image files
- default to
./
viewportScale
: {number} | {Function}- the viewport scale
- in case of a function is specified, the original width & height will be passed in as its arguments
- default to
1.5
config
: {Object}- JPEG encode config
quality
: the quality (0 to 1), default to 0.8progressive
: if progressive compression should be used, default to falsechromaSubsampling
: if chroma subsampling should be used, default to true
- Returns: {Promise} containing the saved file paths {Array{string}}
const result = await pdfCanvas;// => ["images/page-1.jpg", "images/page-2.jpg"]
.toDataURL (options)
- Convert a pdf to PNG / JPEG dataURL asynchronously
options
: {Object}pageRange
: {Array{number}}- the start page number and the last page number
- default to
[1, Infinity]
viewportScale
: {number} | {Function}- the viewport scale
- in case of a function is specified, the original width & height will be passed in as its arguments
- default to
1.5
isPNG
: {boolean}- PNG or JPEG
- default to true
quality
: {number}, optional- the quality (0 to 1)
- default to 0.8
- Returns: {Promise} containing dataURLs {Array{string}}
const result = await pdfCanvas;// => ["data:image/jpeg;base64,...", ...]