Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

poppler-native

sigalor9GPL-2.0-or-later2.3.0

A native interface to the Poppler PDF parser for NodeJS.

readme

Poppler for Node

GitHub license npm Unit tests workflow status

Allows you to use the native Poppler C++ backend to efficiently parse PDF files from NodeJS. Outputs similar information to pdftohtml -xml -stdout test.pdf (with pdftohtml from the poppler-utils package), because it uses parts of the same codebase which have been rewritten to output N-API objects instead of XML code. All contained functions return JavaScript promises.

Getting started

  1. dependencies: build-essential; curl, PNG, JPEG and FreeType development headers; ghostscript, python, mupdf-tools, qpdf
  2. npm install poppler-native (only tested on Ubuntu 16.04 and 20.04 so far)
// allows filename...
const pdf = require('poppler-native');
pdf.info('test.pdf').then(res => console.log(res));

// ...or buffer with raw PDF bytes directly
const fs = require('fs-extra');
fs.readFile('test.pdf')
  .then(f => pdf.info(f))
  .then(res => console.log(res));

// you also have the option to convert the PDF to a PS and then reconvert it to PDF again via GhostScript before extracting data from it, which can sometimes help when wrong characters are extracted with the default method:
pdf.info('test.pdf', { reconvertThroughPS: true });

In order to visualize the parsed text boxes and images, you can also write the entire output from the pdf.info function into a JSON file, then open the file misc/pdf-json-viewer.html in any web browser and drag-and-drop the JSON file there.

Contributing

Updating Poppler

This is obviously only necessary when a new version of Poppler is released. According to their readme, the internal Poppler C++ API, which is the foundation of this project, might be subject to breaking changes, even in minor releases. Consequently, evaluate new Poppler versions thoroughly before updating.

  1. Download the Poppler sources from here.
  2. Put all *.h, *.c and *.cc files from poppler-20.11.0/goo into native/poppler/goo. The same for fofi and poppler. Do not change the existing two config files.
  3. Remove the following files from the native/poppler/poppler directory: CairoFontEngine.cc CairoFontEngine.h CairoOutputDev.cc CairoOutputDev.h CairoRescaleBox.cc CairoRescaleBox.h GlobalParamsWin.cc JPEG2000Stream.cc JPEG2000Stream.h SignatureHandler.cc SignatureHandler.h SplashOutputDev.cc SplashOutputDev.h
  4. Remove the line #include "splash/SplashTypes.h" from native/poppler/poppler/GfxState.cc.

License

GPLv2 or later, because the Poppler source is bundled.

changelog

2.3.0 (2023-09-21)

  • add reconvertThroughPS parameter (Chris031196) #11

2.2.2 (2023-03-06)

  • revert to Poppler 21.05.0

2.2.1 (2023-03-06)

  • fix: do not output page numbers on stdout

2.2.0 (2023-02-17)

  • update Poppler to 23.02
  • update NPM dependencies

2.1.3 (2021-05-26)

  • update Poppler to 21.05.0
  • update NPM dependencies

2.1.2 (2021-05-01)

  • small fix in binding C++ code
  • added misc/pdf-json-viewer.html to visualize the parsing results

2.1.1 (2021-04-23)

  • fix issues with filename input and font extraction

2.1.0 (2021-01-27)

  • implement charmap reconstruction, such that text in the fonts Arial and Arial Bold can now be obtained even if no ToUnicode character map is present in the PDF

2.0.1 (2020-11-03)

  • fix .npmignore to not contain build directory

2.0.0 (2020-11-03)

  • update to Poppler 20.11.0 (the JS API of this package stayed the same, but the information returned by Poppler might be very slightly different now)

1.2.0 (2020-01-28)

  • fixed exception handling from C++ promise and improved Poppler error reporting
  • modified info to accept Buffer input as well and added unit tests for that
  • some internal refactorings

1.1.0 (2020-01-27)

  • renamed readPDF to info, which is now promise-based (refactored internal N-API output object generation for that)
  • added unit tests for minimal test PDF using Jest
  • removed debug flags from node-gyp binding

1.0.0 (2020-01-19)

  • read PDFs from files with Poppler 0.83