npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-pdfbox

v0.1.9

Published

Bridge module to library Apache PDFBox

Downloads

37

Readme

Node PDFBox

node-pdfbox is a bridge library to manipulate PDF based on PDFBox (https://pdfbox.apache.org/)

Installation

Dependencies

This module require JVM configured on host machine to work. When you use this module with nw.js you need to specify this requisite on installation process.

You can use node-pdfbox with NW.js, but don't forget to install JDK to compile java module, after that you can distribute you app in a machine with JVM installed.

npm install --save node-pdfbox

Quick Examples

If you want to call async operations just use the method without Sync suffix.

Sync

  page.extractSync('path.pdf');

Async

  page.extract('path.pdf')
  .then(function() {

  })
  .catch(function(err) {

  })
  .finally(function() {

  });

Basic operations

let Document = require('node-pdfbox');

let document = Document.loadSync('/path/to/document.pdf');
let page = document.getPageSync(0);
let image = page.getImageSync();
let imageScaled = page.getImageSync(2.0);
let imageScaledToFill = page.getImageSync(1300, 1800);

let newDocument = page.extractSync('path-to-new-document.pdf');
newDocument.addPageSync(document.getPageSync(3));
newDocument.addPagesSync(document, 0, 10, 1);

image.fitSync(100, 100).saveSync('path.jpg');
image.cropSync(100, 100).saveSync('path.jpg');
image.cropSync(0, 0, 100, 100).saveSync('path.jpg');
image.cropSync(100, 100, {
  vertical: 'bottom',
  horizontal: 'right'
}).saveSync('path.jpg');

image.saveSync('path.jpeg', 'jpg');

or


Document.load('/path/to/document.pdf')
.then(function(document) {
  return document.getPage(0);
})
.then(function(page) {
  return page.getImage(2.0) //scale
})
.then(function(image) {
  //do something ...
})
.catch(function(err) {
  console.error(err);
})
.finally(function() {
  //Done!
});

Get information


let title = document.getInfoSync('Title');
let title1 = document.getTitleSync(); //The same of getInfo
let author = document.getAuthorSync();
let subject = document.getSubjectSync();
let keywords = document.getKeywordsSync();

Number of pages


let numberOfPages = document.pagesCountSync();

Add pages to document


document.addPageSync(page); //PDFPage to end of file
document.addPageSync('path.pdf', 0, 0); // add page (second) from path (first) at index (third)  

document.addPagesSync('path.pdf'); //Copy all pages from path to end of document
document.addPagesSync(otherDocument); //Copy all pages from PDFDocument
document.addPagesSync(otherDocument, 0); //atIndex
document.addPagesSync(otherDocument, 0, 10, 0); //start, end, atIndex

Save document


document.saveSync(); //save current document
document.saveSync('path.pdf') //save as

Get page


let page = document.getPageSync(0);

Get crop box rect


page.getRectSync();

Get scale to fill


page.getAspectFillScaleSync(100, 100); //width, height

Get scale to fit


page.getAspectFitScaleSync(100, 100); //width, height

Get text


page.getTextSync();

Extract page


let doc = page.extractSync('/path/to/save');

Create image


const scale = 2;

let image = page.getImageSync();
let image1 = page.getImageSync(scale); //scaled
let image2 = page.getImageSync(500, 500); //width, height - crop on center

Fit image


image.fitSync(100, 100).saveSync('/path/to/save');

Crop image


image.cropSync(301, 301).saveSync('/path/to/save');

Save image


image.saveSync('/path/to/save');

Known issues

Before install this module, check whether jvm is installed. To compile this module you need to install JDK.

Not implemented yet

  • Working with Encrypting and signing PDFs
  • Support to create PDF