A utility for converting pdf to image and base64 format.
npm install gix-pdf2pic
npm install -S pdf2pic
`
Usage
$3
`javascript
import { fromPath } from "pdf2pic";
const options = {
density: 100,
saveFilename: "untitled",
savePath: "./images",
format: "png",
width: 600,
height: 600
};
const storeAsImage = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;
storeAsImage(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;
});
`
$3
More usage example can be found here.
pdf2pic API
$3
Initialize PDF to image conversion by supplying a file path
#### Functions
Converts specific page of the PDF to Image/Base64 by supplying a file path
`javascript
fromPath(filePath, options).convert(pageNumber, isBase64)
`
* filePath - pdf file's path
* options - see options.
* pageNumber - page number to be converted to image
* isBase64 - if true, convert() will return base64 output instead
---
Converts PDF to Image/Base64 by supplying a file path
`javascript
fromPath(filePath, options).bulk(pageNumber, isBase64)
`
* filePath - pdf file's path
* options - see options.
* pageNumber - page number/s to be converted to images
* set pageNumber to -1 to select all pages
* pageNumber also accepts an array indicating the page number e.g. [1,2,3]
* also accepts number e.g. 1
* isBase64 - if true, bulk() will return an array of base64 output instead
---
Set GraphicsMagick's subclass or path
`javascript
fromPath(filePath, options).setGMClass(subClass)
`
NOTE: should be called before calling convert() or bulk().
* filePath - pdf file's path
* options - see options.
* subClass - path to gm binary or set to true to use imagemagick
* set subClass to true to use imagemagick
* supply a valid path as subClass to locate gm path specified
---
$3
Initialize PDF to image conversion by supplying a PDF buffer
#### Functions
Converts specific page of the PDF to Image/Base64 by supplying a buffer
`javascript
fromBuffer(buffer, options).convert(pageNumber, isBase64)
`
Functions same as fromPath(filePath, options).convert(pageNumber, isBase64) only input is changed
---
Converts PDF to Image/Base64 by supplying a buffer
`javascript
fromBuffer(buffer, options).bulk(pageNumber, isBase64)
`
Functions same as fromPath(filePath, options).bulk(pageNumber, isBase64) only input is changed
---
Set GraphicsMagick's subclass or path
`javascript
fromBuffer(buffer, options).setGMClass(subClass)
`
Functions same as fromPath(filePath, options).setGMClass(subClass) only input is changed
---
$3
Initialize PDF to image conversion by supplying a PDF base64 string
#### Functions
Converts specific page of the PDF to Image/Base64 by supplying a base64 string
`javascript
fromBase64(b64string, options).convert(pageNumber, isBase64)
`
Functions same as fromPath(filePath, options).convert(pageNumber, isBase64) only input is changed
---
Converts PDF to Image/Base64 by supplying a base64 string
`javascript
fromBase64(b64string, options).bulk(pageNumber, isBase64)
`
Functions same as fromPath(filePath, options).bulk(pageNumber, isBase64) only input is changed
---
Set GraphicsMagick's subclass or path
`javascript
fromBase64(b64string, options).setGMClass(subClass)
`
Functions same as fromPath(filePath, options).setGMClass(subClass)` only input is changed