[publican-list] Changing size of PDF pages

Peter Moulder peter.moulder at monash.edu
Wed Aug 1 05:51:33 UTC 2012


On Fri, Jul 06, 2012 at 03:52:19PM +1000, Jeff Fearn wrote:
> On 07/06/2012 03:26 PM, Jeff Fearn wrote:
> >On 07/06/2012 01:02 PM, Eric Christensen wrote:
> >>Is it possible to set the page size for PDFs in the brand? I'd like
> >>to specify the pages be 6" x 9".
> >
> >[XSL solution for FOP]
> 
> Unless you are using wkhtmltopdf in which case we haven't actually
> considered how to do this.

The standards-based way of doing this would be to add

  @page {
      size: 6in 9in;
  }

to the brand's CSS stylesheet.  That's supported by at least
WeasyPrint and Morp.

If wkhtmltopdf doesn't yet support that, then a hacky approach
would be to have Builder.pm do an imperfect parse of the brand
stylesheet(s) before running wkhtmltopdf, perhaps as simple as:

   $_ = slurp($stylesheet_filename);
   s{/\*.*?\*/}{}g;   # Remove comments first.
   if (/\@page \s* \{ \s*
           size \s* \: ([0-9.]+[a-z]+) \s+
	               ([0-9.]+[a-z]+) \s* (?: \; \s* )?
	\}/xi) {
      push @wkhtmltopdf_args, ('--page-width', $1, '--page-height', $2);
   }

pjrm.




More information about the publican-list mailing list