Skip to content

Commit e17372c

Browse files
authored
Merge pull request #5 from SynergiTech/v1
V1
2 parents 04db3fe + 81af60f commit e17372c

24 files changed

Lines changed: 2894 additions & 569 deletions

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*]
2+
indent_style = space
3+
indent_size = 4
4+
root = true
5+
6+
[*.yml]
7+
indent_style = space
8+
indent_size = 2

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vendor
2+
composer.lock
3+
*.phar
4+
build
5+
.DS_Store
6+
*.cache

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
3+
php:
4+
- '7.1'
5+
- '7.2'
6+
- '7.3'
7+
8+
before_script:
9+
- travis_retry composer self-update
10+
- travis_retry composer install --no-interaction
11+
12+
script:
13+
- vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml
14+
15+
after_success:
16+
- bash <(curl -s https://codecov.io/bash)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Synergi Tech Ltd
3+
Copyright (c) 2019 Synergi Tech Ltd
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,37 @@
1-
# PHP wrapper for chrome-pdf
1+
# PHP ChromePDF Renderer
2+
[![Build Status](https://travis-ci.org/SynergiTech/chrome-pdf-php.svg?branch=master)](https://travis-ci.org/SynergiTech/chrome-pdf-php)
3+
[![codecov](https://codecov.io/gh/SynergiTech/chrome-pdf-php/branch/master/graph/badge.svg)](https://codecov.io/gh/SynergiTech/chrome-pdf-php)
24

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)_
46

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/)
810

11+
## Installation
912
```
1013
composer require synergitech/chrome-pdf-php
1114
```
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.
1217

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.
1820

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.
2823

24+
You should instantiate one of the available drivers, potentially passing options required by the driver:
2925
```php
30-
use SynergiTech\ChromePDF\PDF;
26+
use SynergiTech\ChromePDF\Chrome;
27+
use SynergiTech\ChromePDF\Browserless;
3128

32-
// a controller function
29+
$pdf = new Chrome('path-to-chrome-pdf');
30+
$pdf->renderContent('<h1>test</h1>');
3331

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>');
4434
```
4535

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.

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
],
1212
"require": {
1313
"php": ">=7.1",
14-
"symfony/process": "~3.4|~4.0"
14+
"symfony/process": "~3.4 || ~4.0",
15+
"guzzlehttp/guzzle": "^6.3"
1516
},
1617
"autoload": {
1718
"psr-4": {
18-
"SynergiTech\\ChromePDF\\": "src/"
19+
"SynergiTech\\ChromePDF\\": "src/",
20+
"SynergiTech\\ChromePDF\\Test\\": "test/"
1921
}
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^7.5 || ^8.4",
25+
"friendsofphp/php-cs-fixer": "^2.15"
2026
}
2127
}

examples/laravel.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use SynergiTech\ChromePDF\Browserless;
4+
5+
$contents = view('enquiries.quote', array('enquiry' => $enquiry))->render();
6+
7+
$renderer = new Browserless(getenv('BROWSERLESS_API_KEY'));
8+
$pdf = $renderer->renderContent($contents);
9+
10+
return response($pdf)->withHeaders(array(
11+
'Content-Type' => 'application/pdf',
12+
'Content-Disposition' => 'inline; filename="enquiry.pdf"',
13+
));

phpunit.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
>
12+
<testsuites>
13+
<testsuite name="chrome-pdf-php tests">
14+
<directory suffix="Test.php">./test/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist processUncoveredFilesFromWhitelist="true">
19+
<directory suffix=".php">./src</directory>
20+
<directory suffix=".php">./test/Constraint</directory>
21+
</whitelist>
22+
</filter>
23+
<logging>
24+
<log type="coverage-html" target="build/coverage-html" />
25+
</logging>
26+
</phpunit>

0 commit comments

Comments
 (0)