Skip to content

Node library to merge PDF files into a single PDF document

Notifications You must be signed in to change notification settings

Finamatic/pdf-merge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDFMerge

PDFMerge is a node module used to merge PDF Files into a single PDF Document. It comes in three forms:

  • Buffer
  • ReadStream
  • New file on disk

Traditional callback-style as well as promise is supported.

Requirements

PDFMerge is built using PDFtk and as such it is a requirement in order for PDFMerge to work. PDFMerge will work on any platform supported by PDFtk.

Installing PDFtk

Windows

Download and run the Installer.

Debian, Ubuntu

apt-get install pdftk

RPM

https://www.pdflabs.com/docs/install-pdftk-on-redhat-or-centos/

Usage

By default, pdf-merge will always return a Buffer of the merged PDF document. It does however support ReadStreams and Save-to-File as well. Read the API below.

NOTE: If you are on a Windows platform, you have to specify the absolute path to pdftk.exe. If you are not on Windows platform, the second argument is ignored.

var PDFMerge = require('pdf-merge');
var pdfMerge = new PDFMerge([files], pdftkPath);

//Callback-style
pdfMerge.merge(function(error, result) {
//Handle your error / result here
});

//Promise-style
pdfMerge.promise().then(function(result) {
//Handle result
}).catch(function(error) {
//Handle error
});

API - Main

merge(error, ~result~) -- Callback style. Result is mixed, see the Chainable Options below. By default, a Buffer is always returned.

var pdfMerge = new PDFMerge([...]);
pdfMerge.merge(function(error, result) {});

promise() -- Promise style. Result is mixed, see the Chainable Options below. By default, a Buffer is always returned.

var pdfMerge = new PDFMerge([...]);
pdfMerge.asReadStream().promise()
.then(function(readStream) {...})
.catch(function(error) {...});

API - Chainable Settings

asBuffer() -- Result will be a Buffer of the merged PDF document.

var pdfMerge = new PDFMerge([...]);
pdfMerge.asBuffer().merge(function(error, buffer){...});

asReadStream() -- Result will be a ReadStream of the merged PDF document.

var pdfMerge = new PDFMerge([...]);
pdfMerge.asReadStream().merge(function(error, readStream) {...});

asNewFile(filePath) -- Store the output in a new file at the given filePath.

var pdfMerge = new PDFMerge([...]);
pdfMerge.asNewFile('merged.pdf').merge(function(error, filePath) {...});

keepTmpFile() -- Keep the temporary file that is created when running PDFtk. For whatever reason..

var pdfMerge = new PDFMerge([...]);
pdfMerge.keepTmpFile().merge(function(error, buffer) {...});

About

Node library to merge PDF files into a single PDF document

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •