GithubHelp home page GithubHelp logo

massage's Introduction

Massage

NPM version Downloads Build Status Dependency Status Coverage Status

Dependencies

###ImageMagick and GhostScript

  osx> brew install imagemagick ghostscript
  ubuntu> sudo apt-get install imagemagick ghostscript pdftk

###PDFtk Go to http://www.pdflabs.com/tools/pdftk-server/ for official installation of PDFtk

Usage

#####getMetaData( [Buffer image] ) -> Object

Returns a promise of an object with metadata about the buffer, as told by ImageMagick.

{
  fileType: 'pdf|png|jpg|etc...' [String]
  width: document width in inches [Number]
  length: document length in inches [Number]
  numPages: number of images in the image sequence (number of pages in the PDF) [Number]
}

If ImageMagick's identify tool can't handle the passed buffer, then the promise is rejected.

var myDoc = Fs.readFileSync('myDoc.pdf');
Massage.getMetaData(myPic)
.then(function (data) {
  console.log(data.fileType); // 'PDF'
  console.log(data.width); // '8.5'
  console.log(data.length); // '11'
  console.log(data.numPages); // '2'
});

#####validateUrl( [String url] ) -> String

Returns a promise that is rejected if the given URL is not valid. Otherwise it resolves to the URL.

Massage.validateUrl('https://www.google.com')
.then(function doStuff (url) {
  dependOnURLBeingValid(); // ok
});

#####getBuffer( [String url|Buffer buffer|Object options] ) -> Buffer

Takes a buffer, a URL, or an options object and return a Promise that resolves to a buffer. If you pass an options object it is passed into the request.js constructor, but if you don't supply a method, timeout, or encoding, they default to GET, 10000, and null respectively. The promise always resolves to a buffer which is either the passed buffer or the result of request.js GET'ing the URL.

#####getStream( [String url] ) -> Stream

Takes a URL determines if it is valid and if so returns a readable stream.

If the URL is invalid or request.js fails, the promise is rejected.

#####merge( [Buffer/Stream pdf], [Buffer/Stream pdf] ) -> Stream pdf

Massage.getBuffer('http://internet.site/myPic.jpg')
.then(function (myPic) {
  return Fs.writeFileSync('myPic.jpg', myPic);
});

Merge two PDFs using pdftk and returns a promise which resolves to the resulting rotated pdf (as a stream.)

Could be rejected if pdftk chokes on the files, or you don't have enough disk space to write the results.

#####rotatePdf( [Buffer/Stream pdf], [Number degrees] ) -> Stream pdf

var first  = Fs.readFileSync('firstHalf.pdf');
var second = Fs.readFileSync('secondHalf.pdf');
Massage.merge(first, second)
.then(function (merged) {
  return Fs.writeFileSync('wholeThing.pdf', merged);
});

Returns a promise which resolves to the pdf, rotated clockwise by the given number of degrees. Backed by ImageMagick convert.

Could be rejected if convert chokes on the buffer, or you don't have enough disk space to write the results.

#####burstPdf( [Buffer/Stream pdf] ) -> [Stream]

var wrongWay = Fs.readFileSync('sideways.pdf');
Massage.rotatePdf(wrongWay, 90)
.then(function (rightWay) {
  Fs.writeFileSync('corrected.pdf', rightWay);
});

Takes a multi-page PDF buffer and returns a promise of an array of 1-page pdf streams. Backed by pdftk's burst utility. Always resolves to an array, even if there's just one page in the PDF.

Could be rejected if pdftk chokes on the buffer, or you don't have enough disk space to write the results.

#####imageToPdf( [Buffer/Stream image], [Number dpi] ) -> Stream pdf

Takes a buffer containing an image file and converts it to pdf format at the specified DPI. Returns a promise that resolves to a stream containing the pdf file. Backed by ImageMagick convert.

Could be rejected if convert chokes on the buffer, or you don't have enough disk space to write the results.

var jpegPic = Fs.readFileSync('me.jpg');
Massage.imageToPdf(jpegPic, 300)
.then(function (pdf) {
  // pdf is a pdf of me.jpg
});

massage's People

Contributors

pon avatar bsiddiqui avatar amrit avatar leore avatar graysonchao avatar

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.