Skip to content

Commit b5de22c

Browse files
committed
this should do the trick
0 parents  commit b5de22c

8 files changed

Lines changed: 583 additions & 0 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Synergi Tech Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# PHP wrapper for chrome-pdf
2+
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).
4+
5+
## Installation
6+
7+
The `chrome-pdf` binary should be present on your system and optionally available on your path.
8+
9+
```
10+
composer require synergitech/chrome-pdf-php
11+
```
12+
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+
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+
## Examples
22+
23+
### Laravel Example
24+
25+
```php
26+
use SynergiTech\ChromePDF\PDF;
27+
28+
// a controller function
29+
30+
$contents = view('enquiries.quote', array('enquiry' => $enquiry))->render();
31+
32+
$pdf = new PDF();
33+
34+
$contents = $pdf->getOutputFromHtml($contents);
35+
36+
return response($contents)->withHeaders(array(
37+
'Content-Type' => 'application/pdf',
38+
'Content-Disposition' => 'inline; filename="enquiry.pdf"',
39+
));
40+
```
41+
42+
### FuelPHP Example (converting from Snappy)
43+
44+
```php
45+
46+
// a controller function
47+
48+
$pdf = new \SynergiTech\ChromePDF\SnappyPDF();
49+
50+
$pdf->setOption('displayHeaderFooter', 'true');
51+
$pdf->setOption('header-html', \View::forge('manage/invoices/pdfheader'));
52+
$pdf->setOption('footer-html', \View::forge('manage/invoices/pdffooter')->set(array(
53+
'invoice' => $invoice
54+
)));
55+
$pdf->setOption('margin', '100px 0');
56+
57+
$contents = $pdf->getOutputFromHtml(
58+
\View::forge('manage/invoices/pdfbody')
59+
->set(array(
60+
'invoice' => $invoice,
61+
))
62+
);
63+
return \Response::forge(
64+
$contents,
65+
200,
66+
array(
67+
'Content-Type' => 'application/pdf',
68+
'Content-Disposition' => 'inline; filename="invoice.pdf"'
69+
)
70+
);
71+
```
72+
73+

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "synergitech/chrome-pdf-php",
3+
"type": "library",
4+
"homepage": "https://github.com/SynergiTech/chrome-pdf-php",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Synergi Tech",
9+
"homepage": "http://github.com/SynergiTech"
10+
}
11+
],
12+
"require": {
13+
"php": ">=7.1",
14+
"symfony/process": "~3.4|~4.0"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"SynergiTech\\ChromePDF\\": "src/"
19+
}
20+
}
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace SynergiTech\ChromePDF\Exceptions;
3+
4+
class CannotOverwriteFileException extends \RuntimeException
5+
{
6+
public function __construct(string $filename)
7+
{
8+
parent::__construct(sprintf('File "%s" already exists and this function does not have permission to overwrite it from the arguments', $filename));
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace SynergiTech\ChromePDF\Exceptions;
3+
4+
class InvalidOptionException extends \InvalidArgumentException
5+
{
6+
public function __construct(string $optionname)
7+
{
8+
parent::__construct(sprintf('The option "%s" does not exist', $optionname));
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace SynergiTech\ChromePDF\Exceptions;
3+
4+
class InvalidValueException extends \InvalidArgumentException
5+
{
6+
public function __construct(string $optionname, string $optionvalue)
7+
{
8+
parent::__construct(sprintf('Invalid value "%s" for option "%s"', $optionvalue, $optionname));
9+
}
10+
}

0 commit comments

Comments
 (0)