|
1 | | -# PHP wrapper for chrome-pdf |
| 1 | +# PHP ChromePDF Renderer |
| 2 | +[](https://travis-ci.org/SynergiTech/chrome-pdf-php) |
| 3 | +[](https://codecov.io/gh/SynergiTech/chrome-pdf-php) |
2 | 4 |
|
3 | | -This is a PHP wrapper for [SynergiTech/chrome-pdf](https://github.com/SynergiTech/chrome-pdf) inspired by [KnpLabs/snappy](https://github.com/KnpLabs/snappy). |
| 5 | +_For pre-V1 documentation [click here](https://github.com/SynergiTech/chrome-pdf-php/blob/v0/README.md)_ |
4 | 6 |
|
5 | | -## Installation |
6 | | - |
7 | | -The `chrome-pdf` binary should be present on your system and optionally available on your path. |
| 7 | +This is a library for creating PDFs from HTML rendered with the SkPDF backend via Chrome. In order to do this, you can opt to use one of the supported drivers: |
| 8 | +* [SynergiTech/chrome-pdf](https://github.com/SynergiTech/chrome-pdf) |
| 9 | +* [browserless](https://www.browserless.io/) |
8 | 10 |
|
| 11 | +## Installation |
9 | 12 | ``` |
10 | 13 | composer require synergitech/chrome-pdf-php |
11 | 14 | ``` |
| 15 | +### chrome-pdf |
| 16 | +If you are planning to use the [`chrome-pdf`](https://github.com/SynergiTech/chrome-pdf) driver to render PDFs locally, you should also make sure to install this from npm. |
12 | 17 |
|
13 | | -## Usage |
14 | | - |
15 | | -Instantiate the class, passing the path to the `chrome-pdf` binary if necessary, and apply options in the same way you would with Snappy. |
16 | | - |
17 | | -**Please Note** You must remember to set `displayHeaderFooter` if you want to set either a header or footer and apply margin to make it visible in the PDF. |
| 18 | +### browserless |
| 19 | +If you are planning to use the [browserless](https://www.browserless.io/) driver to render PDFs remotely, you should register for an API key. Remember that local assets cannot be rendered by browserless. |
18 | 20 |
|
19 | | -The available options can be seen in the code. There is also functionality to handle a CSS-style declaring of margins to make input easier. |
20 | | - |
21 | | -### Docker Support |
22 | | - |
23 | | -In order to run chrome-pdf inside a Docker container, you will have to disable the sandbox feature by setting the `sandbox` option to `false`. |
24 | | - |
25 | | -## Examples |
26 | | - |
27 | | -### Laravel Example |
| 21 | +## Usage |
| 22 | +A common interface is provided via AbstractPDF. The options presented via this class will be available from all drivers. |
28 | 23 |
|
| 24 | +You should instantiate one of the available drivers, potentially passing options required by the driver: |
29 | 25 | ```php |
30 | | -use SynergiTech\ChromePDF\PDF; |
| 26 | +use SynergiTech\ChromePDF\Chrome; |
| 27 | +use SynergiTech\ChromePDF\Browserless; |
31 | 28 |
|
32 | | -// a controller function |
| 29 | +$pdf = new Chrome('path-to-chrome-pdf'); |
| 30 | +$pdf->renderContent('<h1>test</h1>'); |
33 | 31 |
|
34 | | -$contents = view('enquiries.quote', array('enquiry' => $enquiry))->render(); |
35 | | - |
36 | | -$pdf = new PDF(); |
37 | | - |
38 | | -$contents = $pdf->getOutputFromHtml($contents); |
39 | | - |
40 | | -return response($contents)->withHeaders(array( |
41 | | - 'Content-Type' => 'application/pdf', |
42 | | - 'Content-Disposition' => 'inline; filename="enquiry.pdf"', |
43 | | -)); |
| 32 | +$pdf = new Browserless('your-api-key'); |
| 33 | +$pdf->renderContent('<h1>test</h1>'); |
44 | 34 | ``` |
45 | 35 |
|
46 | | -### FuelPHP Example (converting from Snappy) |
47 | | - |
48 | | -```php |
49 | | - |
50 | | -// a controller function |
51 | | - |
52 | | -$pdf = new \SynergiTech\ChromePDF\SnappyPDF(); |
53 | | - |
54 | | -$pdf->setOption('displayHeaderFooter', 'true'); |
55 | | -$pdf->setOption('header-html', \View::forge('manage/invoices/pdfheader')); |
56 | | -$pdf->setOption('footer-html', \View::forge('manage/invoices/pdffooter')->set(array( |
57 | | - 'invoice' => $invoice |
58 | | -))); |
59 | | -$pdf->setOption('margin', '100px 0'); |
60 | | - |
61 | | -$contents = $pdf->getOutputFromHtml( |
62 | | - \View::forge('manage/invoices/pdfbody') |
63 | | - ->set(array( |
64 | | - 'invoice' => $invoice, |
65 | | - )) |
66 | | -); |
67 | | -return \Response::forge( |
68 | | - $contents, |
69 | | - 200, |
70 | | - array( |
71 | | - 'Content-Type' => 'application/pdf', |
72 | | - 'Content-Disposition' => 'inline; filename="invoice.pdf"' |
73 | | - ) |
74 | | - ); |
75 | | -``` |
| 36 | +## Examples |
| 37 | +Some examples can be found in the `examples` folder. |
0 commit comments