0

I am trying to use Snappy PDF from barrvdh to make and download PDF file from HTML code. This is my code

public function example()
{
    $pdf = \PDF::loadView('index');
    return $pdf->download('test.pdf');
}

Like the title, when user click button to download pdf, i want to put all content in only one page and set page size to A3. With dompdf, i can easy to set page size in dompdf.php, like below:

"default_paper_size" => "a4",

But i don't know how to set page size and put content in single page with snappy.
Thanks,

hayumi kuran
  • 391
  • 9
  • 21

1 Answers1

0

There is a pretty good explaination of how to zoom and fit everything into one page in an old answer for wkhtmltopdf which is the underlying machine for Snappy PDF, seen here. This will help you with the detail on the mechanics of setting it into one page.

To directly answer your question, setting options like page size in snappy is just entering parameters into the method of your choice like this:

$pdf = \PDF::loadView('index', $myVar)->setOption('margin', 5)->setOrientation('landscape')->setPaper('a4');

The interface, while excellent, does leave a little guesswork to translate between wkhtmltopdf and how to get those options into Snappy, but the above should get you pretty close to where you want to go. You may need to review the wkhtmltopdf options, and then peek at the Snappy source code for some more unusual ones, but the basics are in the code above.

Watercayman
  • 7,970
  • 10
  • 31
  • 49