Skip to content

Commit

Permalink
Improve pdf engines
Browse files Browse the repository at this point in the history
  • Loading branch information
8ctopus committed May 1, 2024
1 parent 8c0fe1f commit 695592a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ $pdf = $invoice->renderPdf([
'orientation' => 'portrait',
// allow to download content from the internet such as fonts
'isRemoteEnabled' => true,
// uncomment to use wk\<html\>topdf
//'engine' => 'alternate',
// valid options: CPDF, PDFLib, GD, wkhtmltopdf and auto
'pdfBackend' => 'CPDF',
]);

file_put_contents('invoice.pdf', $pdf);
```

## wk\<html\>topdf
## pdf engines

- `CPDF` is included within `DomPdf`
- `PDFLib` is a commercial library https://www.pdflib.com/ that needs to be installed
- `GD` will make a graphic pdf
- `wk<html>topdf`

To use the `wk<html>topdf` engine, you will need to [download the binary](https://wkhtmltopdf.org/downloads.html) for your system and add it to the current working directory `getcwd()` or to the system path.

Expand Down
2 changes: 1 addition & 1 deletion demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
'isRemoteEnabled' => true,
'cache' => $cache,
'debug' => true,
//'PDFLib', 'CPDF', 'GD', and 'auto'
// valid options: CPDF, PDFLib, GD, wkhtmltopdf and auto
'pdfBackend' => 'CPDF',
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function renderHtml() : string
*/
public function renderPdf(array $options = []) : string
{
if (array_key_exists('engine', $options) && $options['engine'] === 'alternate') {
if (($options['engine'] ?? '') === 'wkhtmltopdf') {
return $this->renderWK($options);
}

Expand Down

0 comments on commit 695592a

Please sign in to comment.