node-poppler
Intro
The node-poppler module was created out of a need for a PDF-to-HTML conversion tool at Yeovil District Hospital NHSFT to convert clinical documents to HTML.
This allows the documents to be dispatched electronically via the NHS MESH system to other NHS bodies.
There are a number of other Poppler wrapper modules available but the majority are no longer maintained or did not provide full interfacing with the Poppler binaries (i.e. only provided an interface to the PDF-to-Cairo binary but not to HTML).
What is Poppler?
Poppler is an open-source software utility library for rendering PDF documents; poppler-utils are a collection of binaries built on Poppler for manipulating, extracting from, and converting PDF documents to a variety of formats including HTML, PNG, JPEG, TIFF, PDF, PS, EPS, SVG, BMP, and TXT.
Installation
Install using yarn
:
yarn add node-poppler
Or npm
:
npm install node-poppler
node-poppler's test scripts use yarn commands.
API
API Documentation can be found here
Example uses
poppler.pdfToCairo
options
object requires atleast one of the following to be set: jpegFile
; pdfFile
; pngFile
; psFile
; svgFile
; tiffFile
.
Example of calling poppler.pdfToCairo with a promise:
const { Poppler } = require('node-poppler');
const file = 'test_document.pdf';
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2,
pngFile: true
};
await poppler.pdfToCairo(options, file)
.then((res) => {
console.log(res);
});
poppler.pdfToHtml
Every field of the options
object is entirely optional.
Example of calling poppler.pdfToHtml with a promise:
const { Poppler } = require('node-poppler');
const file = 'test_document.pdf';
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2
};
await poppler.pdfToHtml(options, file)
.then((res) => {
console.log(res);
});
poppler.pdfToText
Every field of the options
object is entirely optional.
Example of calling poppler.pdfToText with a promise:
const { Poppler } = require('node-poppler');
const file = 'test_document.pdf';
const poppler = new Poppler();
const options = {
firstPageToConvert: 1,
lastPageToConvert: 2
};
await poppler.pdfToText(options, file)
.then((res) => {
console.log(res);
});
License
node-poppler
is licensed under the MIT license.