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

pdfjam

v0.1.0

Published

Pdf manipulation using pdfjam

Downloads

44

Readme

node-pdfjam

Npm package for using pdfjam utilities.

This project for now mainly implements the 'nup' capabilities. It can merge multiple pdfs into one, and also merge pages of pdfs so 4 pages would appear in one for example. More info here

Here is a demonstration

/* We are using await / async syntax here from node 8+, you can also use Promise syntax instead */
const pdfjam = require('pdfjam');

async function main() {
    /* Standard conversion of pdf with pages in a 2x2 layout */
    await pdfjam.nup('file.pdf', 2, 2,  {
        /* Suffix the new pdf file will have, `${originalName}-{suffix}.pdf`, by default is 'nup' */
        suffix: '2x2'
    });

    /* Just merge files, no page layout. Suffix is "pdfjam" in this case */
    await pdfjam(['file1.pdf', 'file2.pdf', 'file3.pdf'],  {
        // nup : "2x2" <- nup can be used through options
        // default suffix is "pdfjam" here
        // In fact the options argument is never mandatory
    });

    /* Conversion of pdf with pages in a 1x2 layout */
    await pdfjam.nup('file.pdf', 1, 2,  {
        /* Destination file, overrides suffix */
        outfile: 'file-converted.pdf'
    });

    /* Output in landscape mode, with paper size specified (by default A4) */
    await pdfjam.nup('file.pdf', 2, 1,  {
        orientation: 'landscape',
        papersize: '{1920px,1080px}' /* Can also use cm as unit */
        scale: 0.9 /* Reduce input page sizes a bit */
    });

    /* Merge multiple files in one, with the output a layout of 2x2 */
    await pdfjam.nup(['file1.pdf', 'file2.pdf', 'file3.pdf'], 2, 2,  {
        scale: 0.9 /* Reduce input page sizes a bit */
    });

    /* Merge multiple slides and adjust margins */
    await pdfjam(['slide1.pdf', 'slide2.pdf', 'slide3.pdf', 'slide4.pdf', 'slide5.pdf'], {
        outfile: "slides.pdf",
        trim: "-6cm -1cm 13cm 8cm",
        scale: 0.4
    });
}

main().then(() => {
    console.log("All done!");
})

Requirements

Pdfjam is needed. On debian systems, you can get it like that:

sudo apt install texlive-extra-utils

Note that this installs 600MB of software if you don't already have a LaTeX infrastructure.

Node version 8+ is expected. If you want to update your node version, you can do:

sudo npm install -g n
sudo n stable

Installation

Run this in your project directory:

npm i pdfjam  #add --save if your npm is < 5.0

Documentation

All functions return promises. The output directory of pdfjam is the working directory of your program (process.cwd()), but you can specify an absolute path in the outfile option.

pdfjam(input: string | string[], options: object)

Invokes pdfjam with the input given. If an array of strings is given as input, then the input files will be merged in the output, unless the batch options is provided, in which case there will be as many output files as input files.

Here are the valid values for options:

  • suffix {string = 'pdfjam'}: What to append to the input filename to get the output filename. Overriden by the outfile option. Default value is "pdfjam". The output file name will look like basename-suffix.pdf.
  • outfile {string}: Output pdf file, overrides suffix if supplied.
  • orientation {'portrait'|'landscape'} : Orientation of the output.
  • batch {boolean = false}: If set to true, will process each input file individually and produce an output file for each.
  • scale {number = 1.0}: Can resize the pages of the input in the output.
  • papersize {string = "{21cm,29.7cm}"}: Size of the pages in the output. Unit can be cm or px or in.
  • trim {string = "0cm 0cm 0cm 0cm"}: Remove margins from the input pages. Can also add margins by using negative numbers.
  • nup {string = "1x1"}: Page layout in the output pdf.

pdfjam.nup (input: string | string[], rows: number, cols: number, options: object)

Helper for page layout. Calls pdfjam with the nup option, as well as the provided options, and if no suffix or outfile is provided, will set the suffix to "nup".

Contributing

There are many more options that can easily be added to the module, such as paper type (paper: 'a4paper') or page color.

I very welcome contributions or even taking over of the project. This project was made in order to fill one of my particular needs, the use of pdfnup, so I welcome any contribution adding more of pdjam's features.

I also welcome any contribution in the form of tests, travis integration, using a build script to make the project compatible with older node versions and so on.