GithubHelp home page GithubHelp logo

pdfgenerator's Introduction

README

What is pdf-generator ?

Simple webservice to generate pdf from html using wkhtml library. Basically there is only one file in this project, it takes in parameter an url and directly outputs the pdf content in the answer.

Installation

  1. Package wkhtml : C++ lib which converts html into pdf. Uses WebKit as render engine.
sudo apt-get install wkhtmltopdf
  1. Package xvfb : X Server used by wkhtmltopdf
sudo apt-get install xvfb xauth
  1. (OPTIONNAL) Package Ghostscript : Ghostscript is mandatory for option cmyk=1 (CMYK pdf output)
sudo apt-get install ghostscript
  1. Get project on git
git clone [email protected]:CanalTP/pdfGenerator.git
  1. Run composer
composer.phar install
  1. Use it!

Requirements

knplabs/knp-snappy: https://github.com/KnpLabs/snappy

Usage

Call index.php and give in parameter the url to convert into pdf. Example (without vhost):

http://localhost/pdfGenerator/web/index.php?url=http://www.example.org

You can also omit the scheme (AKA the protocol)

http://localhost/pdfGenerator/web/index.php?url=google.fr

If your url contains GET parameters, you need to encode it (using encodeURIComponent for instance) so it will look like this

http://localhost/pdfGenerator/web/index.php?url=https%3A%2F%2Fwww.phpbb.com%2Fabout%2Ffeatures%2F%3Ffrom%3Dsubmenu

Wkhtml has many parameters to refine the pdf generation as you can see here:

http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html

All these parameters may be sent to the webservice:

http://localhost/pdfGenerator/web/index.php?url=google.fr&orientation=landscape&zoom=2

Options

Optionnal url get parameters could be sent to pdfGenerator:

  • margin : Will set CSS document sheet margin
  • cmyk : When set to 1 or True, the returned pdf will use CMYK colorspace (usefull for offset or Web professionnal printers)
  • ddl : Will force your browser to download the file. The value of the parameter will be the name of the downloaded file.

Additionnaly all wkhtmltopdf options are available (See http://wkhtmltopdf.org/usage/wkhtmltopdf.txt) Several options have an overloaded default value :

  • lowquality : false
  • disable-javascript : true
  • disable-smart-shrinking : true
  • print-media-type : true

Remarks

By default there is no javascript to minimize resources consumption.You can re-enable it by setting disable-javascript to false.

TODO

Securize this webservice using apache vhost, limit to a specific range of ip for instance.

TODO?

Check if the url exists and returns a valid http code? Add an option to enable javascript if needed?

Contributing

  1. Vincent Degroote - [email protected]

pdfgenerator's People

Contributors

xavierraffin avatar netmisa avatar datanel avatar ooga avatar thierrymarianne avatar vchabot avatar

Watchers

Sadhan Sarker 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.