Add Recall Data to Appointment Widget
[openemr.git] / vendor / knplabs / knp-snappy / README.md
blobd1a1b6cd0c9def013ebe6a6d7e599cf8f812d0df
1 # Snappy
3 Snappy is a PHP 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://wkhtmltopdf.org/)
5 available on OSX, linux, windows.
7 You will have to download wkhtmltopdf `0.12.x` in order to use Snappy.
9 Please, check [FAQ](doc/faq.md) before opening a new issue. Snappy is a tiny wrapper around wkhtmltox, so lots of issues are already answered, resolved or wkhtmltox ones.
11 [![Build Status](https://secure.travis-ci.org/KnpLabs/snappy.png?branch=master)](http://travis-ci.org/KnpLabs/snappy)
13 ## Installation using [Composer](http://getcomposer.org/)
15 ```bash
16 $ composer require knplabs/knp-snappy
17 ```
19 ## Usage
21 ```php
22 <?php
24 require __DIR__ . '/vendor/autoload.php';
26 use Knp\Snappy\Pdf;
28 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
30 // or you can do it in two steps
31 $snappy = new Pdf();
32 $snappy->setBinary('/usr/local/bin/wkhtmltopdf');
34 // Display the resulting pdf in the browser
35 // by setting the Content-type header to pdf
36 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
37 header('Content-Type: application/pdf');
38 header('Content-Disposition: attachment; filename="file.pdf"');
39 echo $snappy->getOutput('http://www.github.com');
41 // Merge multiple urls into one pdf
42 // by sending an array of urls to getOutput()
43 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
44 header('Content-Type: application/pdf');
45 header('Content-Disposition: attachment; filename="file.pdf"');
46 echo $snappy->getOutput(array('http://www.github.com','http://www.knplabs.com','http://www.php.net'));
48 // .. or simply save the PDF to a file
49 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
50 $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');
52 // Pass options to snappy
53 // Type wkhtmltopdf -H to see the list of options
54 $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
55 $snappy->setOption('disable-javascript', true);
56 $snappy->setOption('no-background', true);
57 $snappy->setOption('allow', array('/path1', '/path2'));
58 $snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));
59 $snappy->setOption('post', array('key' => 'value'));
60 $snappy->setOption('cover', 'pathToCover.html');
61 // .. or pass a cover as html
62 $snappy->setOption('cover', '<h1>Bill cover</h1>');
63 $snappy->setOption('toc', true);
64 $snappy->setOption('cache-dir', '/path/to/cache/dir');
65 ```
67 ## wkhtmltopdf binary as composer dependencies
69 If you want to download wkhtmltopdf and wkhtmltoimage with composer you add to `composer.json`:
71 ```bash
72 $ composer require h4cc/wkhtmltopdf-i386 0.12.x
73 $ composer require h4cc/wkhtmltoimage-i386 0.12.x
74 ```
76 or this if you are in 64 bit based system:
78 ```bash
79 $ composer require h4cc/wkhtmltopdf-amd64 0.12.x
80 $ composer require h4cc/wkhtmltoimage-amd64 0.12.x
81 ```
83 And then you can use it
85 ```php
86 <?php
88 use Knp\Snappy\Pdf;
90 $myProjectDirectory = '/path/to/my/project';
92 $snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386');
94 // or
96 $snappy = new Pdf($myProjectDirectory . '/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
97 ```
99 *N.B.* These static binaries are extracted from  [Debian7 packages](https://github.com/h4cc/wkhtmltopdf-amd64/issues/13#issuecomment-150948179), so it might not be compatible with non-debian based linux distros 
100 ## Some use cases
102 If you want to generate table of contents and you want to use custom XSL stylesheet, do the following:
104 ```php
105 <?php
106 $snappy = new Pdf('/path/to/binary');
108 $snappy->setOption('toc', true);
109 $snappy->setOption('xsl-style-sheet', 'http://path/to/stylesheet.xsl') //or local file;
111 $snappy->generateFromHtml('<p>Some content</p>', 'test.pdf');
114 ## Credits
116 Snappy has been originally developed by the [KnpLabs](http://knplabs.com) team.