Giter VIP home page Giter VIP logo

pdf2jpg's Introduction

PDF2JPG

Convert PDF pages to a single jpg by using pdf.js and node-canvas.

Online demo

https://pdf2jpg.sijie.wang/?url={url_for_pdf_file}

e.g. https://pdf2jpg.sijie.wang/?url=https://pdf2jpg.sijie.wang/sample.pdf

Installation

Require canvas, see https://github.com/Automattic/node-canvas for installation guide.

In most systems, this can be done by the single command:

npm i pdf2jpg

Usage

const pdf2jpg = require('pdf2jpg');
const fs = require('fs');

const source = fs.readFileSync('test.pdf'); // can be buffer or just url
pdf2jpg(source).then(buffer => fs.writeFileSync('out.jpg', buffer))
// page 1 only (starts from 1)
pdf2jpg(source, { page: 1 }).then(buffer => fs.writeFileSync('out-page-1.jpg', buffer))

Development

docker build -t pdf2jpg .
docker run -it -v $(pwd):/app pdf2jpg

Thanks to

https://github.com/mozilla/pdf.js/blob/master/examples/node/pdf2png/pdf2png.js

https://gist.github.com/jdeng/cbfad9cb21e452127c81

https://github.com/jwerre/node-canvas-lambda

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.