Skip to content

ooga/pdfGenerator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  2. Package xvfb : X Server used by wkhtmltopdf. sudo apt-get install xvfb

  3. (OPTIONNAL) Package Ghostscript : Ghostscript is mandatory for option cmyk=1 (CMYK pdf output) sudo apt-get install ghostscript

  4. Get project on git git clone https://hg.prod.canaltp.fr/ctp/pdfGenerator.git

  5. Run composer composer.phar install

  6. 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):

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

You can also omit the scheme (AKA the protocol)

https://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

https://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:

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

All these parameters may be sent to the webservice:

https://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)

Additionnaly all wkhtmltopdf options are available (See https://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]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%