Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust PDF options for PhantomJS

Tags:

pdf

phantomjs

I use PhantomJS for PDF generation.

This is my command:

./phantomjs rasterize.js <someurl> test.pdf

It generates pdf file but:

  1. The PDF looks nothing like the original website
  2. I can't set the page orientation
  3. Also is there any other options I can use for pdf generation?

The following change to rasterize.js also doesn't seem to work:

{ format: system.args[3], orientation: 'Letter', margin: '1cm' }
like image 745
Oleksandr IY Avatar asked May 12 '13 09:05

Oleksandr IY


1 Answers

Rasterize.js is a very basic example of screen capture. There are some default values in this example that you can change to your needs.

  • page.viewportSize

Simulates the size of the window like in a traditional browser. In rasterize.js, it's { width: 600, height: 600 } ; not a common resolution and you may need to change this.

  • page.paperSize

Defines the size of the web page when rendered as a PDF. There are two modes : Manual (given a width and a height) or automatic (given a format). Do not hesitate to read the webpage documentation and the wiki page.

In your case, orientation: 'Letter' is invalid. Supported formats are 'A3', 'A4', 'A5', 'Legal', 'Letter', 'Tabloid'. Supported orientation are 'portrait' and 'landscape'.

Take a look at the source code and change it to your needs !

like image 179
Cybermaxs Avatar answered Sep 28 '22 09:09

Cybermaxs