commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / snappy / README.markdown
1 # Snappy
2
3 Snappy is a PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page.
4 It uses the excellent webkit-based [wkhtmltopdf and wkhtmltoimage](http://code.google.com/p/wkhtmltopdf/)
5 available on OSX, linux, windows.
6
7 You will have to download wkhtmltopdf 0.10.0 >= rc2 in order to use Snappy.
8
9 ## Usage
10
11 ```php
12 <?php
13
14 require_once '/path/to/snappy/src/autoload.php';
15
16 use Knp\Snappy\Pdf;
17
18 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
19
20 // or you can do it in two steps
21 $snappy = new Pdf();
22 $snappy->setBinary('/usr/local/bin/wkhtmltopdf');
23
24 // Display the resulting image in the browser
25 // by setting the Content-type header to jpg
26 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
27 header('Content-Type: application/pdf');
28 header('Content-Disposition: attachment; filename="file.pdf"');
29 echo $snappy->getOutput('http://www.github.com');
30
31 // .. or simply save the PDF to a file
32 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
33 $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');
34
35
36 // Pass options to snappy
37 // Type wkhtmltopdf -H to see the list of options
38 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
39 $snappy->setOption('disable-javascript', true);
40 $snappy->setOption('no-background', true);
41 $snappy->setOption('allow', array('/path1', '/path2'));
42 $snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));
43 ```
44
45 ## Credits
46
47 Snappy has been originally developed by the [KnpLabs](http://knplabs.com) team.