1.0.2 ā€¢ Published 9 months ago

@hyzyla/pdfium v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@hyzyla/pdfium

šŸ“ƒ Documentation

Node.js wrapper for the PDFium library:

  • ā¬‡ļø pdfium - source code of the PDFium library, developed by Google and used in Chrome.
  • ā¬‡ļø pdfium-lib - project to compile PDFium library to multiple platforms, including WebAssembly.
  • šŸ“ @hyzyla/pdfium - (you are here) Node.js wrapper for the WebAssembly build of PDFium library.

Features

@hyzyla/pdfium is a Node.js wrapper for the PDFium library:

  • ā¬‡ļø pdfium - an open-source library for PDF manipulation and rendering, developed by Google and used in Google Chrome browser.
  • ā¬‡ļø pdfium-lib - project by Paulo Coutinho to compile PDFium library to multiple platforms, including WebAssembly.
  • šŸ“ @hyzyla/pdfium - (you are here) Node.js wrapper for the WebAssembly build of PDFium library.

Installation

# yarn add @hyzyla/pdfium
# pnpm install @hyzyla/pdfium
npm install @hyzyla/pdfium

Usage

import { PDFiumLibrary } from "@hyzyla/pdfium";
import { promises as fs } from 'fs';

async main() {
  const buff = await fs.readFile('test2.pdf')

  // Initialize the library, you can do this once for the whole application
  // and reuse the library instance.
  const library = await PDFiumLibrary.init();;

  // Load the document from the buffer
  // You can also pass "password" as the second argument if the document is encrypted.
  const document = await library.loadDocument(buff);

  // Iterate over the pages, render them to PNG images and
  // save to the output folder
  for (const page of document.pages()) {
    console.log(`${i + 1} - rendering...`);

    // Render PDF page to PNG image
    const image = await page({
      scale: 3, // 3x scale (91 DPI is the default)
      render: 'sharp', // use "sharp" for converting bitmap to PNG
    });

    // Save the PNG image to the output folder
    await fs.writeFile(`output/${i + 1}.png`, image.data);
  }

  // Do not forget to destroy the document and the library
  // when you are done.
  document.destroy();
  library.destroy();
}

main();

Deploy

  1. Bump version in package.json
  2. Create a new release in GitHub
  3. Check status of the GitHub Actions
1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.3

11 months ago

0.0.1

12 months ago