bauhausjs / phantom-html2pdf

Node module to generate PDFs from HTML via PhantomJS
MIT License
112 stars 47 forks source link

paperSize option doesn't work #41

Closed andrea-teom closed 7 years ago

andrea-teom commented 7 years ago

set options 'paperSize': {format: 'A4', orientation: 'landscape'} orientation result is portrait

dustin-H commented 7 years ago

Hi there, how exactly have you done this?

andrea-teom commented 7 years ago

I render a page with mustaches inside a post request (with express)

html = ...;
var option = {
...
'paperSize': {format: 'A4', orientation: 'landscape'}
}
pdf.convert(options, function(err, result) {
    /* Using the file writer and callback */
    result.toFile("/path/to/file.pdf", function() {});
});
dustin-H commented 7 years ago

Hi @andrea-teom

I did it like this, and it worked:

'use strict';

var pdf = require('phantom-html2pdf');

var pdfOptions = {
  html: '<!DOCTYPE html><html lang="en"><body><h1>Hello</h1><p>World</p></body></html>',
  paperSize: {
    format: 'A4',
    orientation: 'landscape',
    border: '1cm'
  }
};

pdf.convert(pdfOptions, function(err, result) {
  result.toFile("./file.pdf", function() {
    console.log('Done');
  });
});