Giter Club home page Giter Club logo

ghostscript-node's Introduction

ghostscript-node

GitHub license npm

Introduction

A fully promise-based Node.js library which can work with PDFs, based on Ghostscript and qpdf.

All PDF files that are handled by this library in the form of Buffer objects, i.e. to a user of this library, it looks like everything works only in memory. In the background though, file system access (via tempy) is needed.

Additionally, this library requires the gs command (Ghostscript) as well as qpdf to be available.

Getting started

npm install ghostscript-node

Usage

const gs = require("ghostscript-node");

(async () => {
  const pdf1 = /* load first PDF as Buffer, e.g. from database */;
  const pdf2 = /* load second PDF as Buffer, e.g. from database */;

  // get Buffer object with bytes of combined PDF
  const combinedPDF = await gs.combinePDFs([pdf1, pdf2]);

  // get number of pages of pdf1
  const numPagesPDF1 = await gs.countPDFPages(pdf1);

  // get Buffer object with bytes of specified set of pages
  // page numbers begin with 1, last page is included
  const partOfPDF1 = await gs.extractPDFPages(pdf1, 3, 5);

  // rotate all pages of pdf1 by 90 degrees clockwise
  const rotatedPDF = await gs.rotatePDF(pdf1, "90");

  // returns an array of buffers containing PNG images of the desired pages
  const renderedPages = await gs.renderPDFPagesToPNG(pdf1);

  // checks if pdf1 is a valid PDF file
  const isPDF1Valid = await gs.isValidPDF(pdf1);
})();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.