Git Product home page Git Product logo

pdfkitjs's Introduction

Deprecation warning

deprecated This module is old and the API is not really consistent. I recommend you to use: https://github.com/devongovett/node-wkhtmltopdf

PDFKitJs

Create PDFs using plain old HTML+CSS. Uses wkhtmltopdf on the back-end which renders HTML using Webkit.

Hightly inspired by PDFKit written in Ruby

Install

PDFKit

npm install pdfkitjs

wkhtmltopdf

https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF

Usage

// PDFKit support multiples types (url, file, html) and any options for wkhtmltopdf
// run `wkhtmltopdf --extended-help` for a full list of options
var PDFKit = require('pdfkitjs');

pdf = new PDFKit('url', 'http://google.com');

pdf.toFile('google.pdf', function (err, file) {
  console.log('File ' + file + ' written');
});

API

PDFKit(type, url_file_or_html[, options[, spawnOptions[, logger]]])

options : Object corresponding on wkhtmltopdf arguments. run wkhtmltopdf --extended-help for a full list of options

spawnOptions : Options passed to child_process.spawn except exec who is the path to the wkhtmltopdf binary. (Default: wkhtmltopdf)

  • url
new PDFKit('url', 'http://google.com')
  • file
new PDFKit('file', 'path/to/some.html')
  • html
new PDFKit('html', '<h1>Hello</h1>')

Logger

You can pass a logger object that implemnts log, warn, debug methods. Default logger:

var baseLogger = {
  log: console.log,
  warn: console.warn,
  debug: console.log
};

To silent all logs, you can pass false.

Output

TODO

Copyright

Copyright (c) 2010 Loïc Mahieu.

pdfkitjs's People

Contributors

loicmahieu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pdfkitjs's Issues

Potential Command Injection Vulnerability in pdfkitjs

Hi,

Thanks for developing this great npm package! We find a potential command injection vulnerability from it.
The bug is introduced because the package-exported method allows external input to overwrite the internal configuration property spawnOptions.exec , which finally flows into a command execution API.

Here is the proof of concept.

const pdfkit = require("pdfkitjs");
pdfkit("", "", {}, {exec:"touch /tmp/pdfkitjs-rce", shell: true},"").toFile("", function () {}) 

code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn'

my code 👍

  var PDFKit = require('pdfkitjs');

var pdf = new PDFKit('url', 'http://google.com');

pdf.toFile('google.pdf', function (err, file) {
    console.log(err);
    console.log('File ' + file + ' written');
});

TypeError: Cannot define property:48, object is not extensible

    at normalize (/Users/juanjesusc/Documents/ceramic-pro/react/node_modules/pdfkitjs/node_modules/temporary/lib/detector.js:23:34)
    at Object.detector.tmp (/Users/juanjesusc/Documents/ceramic-pro/react/node_modules/pdfkitjs/node_modules/temporary/lib/detector.js:43:10)
    at Object.generator.build (/Users/juanjesusc/Documents/ceramic-pro/react/node_modules/pdfkitjs/node_modules/temporary/lib/generator.js:45:27)
    at File.Base.init (/Users/juanjesusc/Documents/ceramic-pro/react/node_modules/pdfkitjs/node_modules/temporary/lib/base.js:31:28)
    at new File (/Users/juanjesusc/Documents/ceramic-pro/react/node_modules/pdfkitjs/node_modules/temporary/lib/file.js:23:8)
    at new PDFKit (/Users/juanjesusc/Documents/ceramic-pro/react/node_modules/pdfkitjs/lib/pdfkit.js:49:19)

Upgrading to temporary-0.0.8 fixes it.

toFile is not a function

Hi,

I have following code in my project. But this shows error "pdf.toFile is not a function"

var PDFKit = require('pdfkit');

    pdf = new PDFKit('html', html);

    pdf.toFile('google.pdf', function (err, file) {
      console.log('File ' + file + ' written');
    });

Cannot find module 'pdfkitjs'

In the npm page, docs state that you should require('pdfkitjs');, that doesn't work but require('pdfkit'); does, why is that?

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.