3

I'm using DOMPDF on a little web app I'm building. It's working great apart from it's stuck on the default paper size of 'US Letter' no matter where I change it.

Any ideas?

// dompdf_config.inc.php
def("DOMPDF_DEFAULT_PAPER_SIZE", "a4");
Deej
  • 105
  • 1
  • 1
  • 9
  • See that this is answered, but ... the default paper size set in the config not honored? – BrianS Jul 16 '13 at 20:02
  • it was being ignored yes ... strange I know ... you had this? – Deej Jul 23 '13 at 19:04
  • I haven't experienced this, but if it is a persistent problem it's something we'll want to look into (I work on the project). – BrianS Jul 23 '13 at 20:40
  • It does look like dompdf ignores the default size and uses letter. The default is probably being superseded during initialization. I've posted a [bug report](https://github.com/dompdf/dompdf/issues/687), which you can follow if you want to know when the issue is addressed. As noted in the accepted answer you can manually specify the page size. – BrianS Jul 25 '13 at 20:43

2 Answers2

10

Are you correctly calling the 'set_paper' method in your pdf creation as follows :

$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait');

Furthermore, you can define your own paper size if this is still not working using something along the lines of the following :

$paper_size = array(0,0,360,360);
$dompdf->set_paper($paper_size);
Hannele
  • 9,301
  • 6
  • 48
  • 68
Tom Metcalfe
  • 308
  • 1
  • 3
  • 12
  • Ahhh shocking N00B mistake I just had: $this->pdf->core->set_paper('a4'); – Deej Jul 16 '13 at 16:18
  • How about setting the Creator? So I can change it to my app's name instead of "DOMPDF"? – Deej Jul 16 '13 at 16:19
  • I'm not sure how to add a creator, i'm not sure if the built in functionality is there for that option. I do know you can set the PDF title and author with something such as this "$dompdf->add_info('Author', 'Author Name Here');" So there may be a 'Creator' option but I can't be 100% sure without testing any code. – Tom Metcalfe Jul 16 '13 at 16:27
  • In fact after a quick look through the dompdf.cls.php file you can see that at line 911 the supported labels are shown which are 'author', 'keywords' and 'description'. But keeping DOMPDF as the creator is a good way of supporting such a fantastic and free library. – Tom Metcalfe Jul 16 '13 at 16:29
  • Oh I know that, I wouldn't take them out, but append. It's only for an internal web app anyway. See what you make of [this](http://stackoverflow.com/questions/17682119/font-glyph-outline-error-when-using-webfonts-with-dompdf) too good sir? – Deej Jul 16 '13 at 16:32
8

The above did not help me still stuck on Letter The following did work (from DOMPDF FAQ)

$dompdf->set_paper("A4", "portrait");
zzapper
  • 4,743
  • 5
  • 48
  • 45
  • 1
    I ended up switching libs to WkHtmlToPdf ... had a look into that? It's pretty comprehensive, and supports a lot more css than other engines. – Deej Mar 03 '14 at 20:17