Skip to content
Merged

Next #338

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install packages
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: xfonts-base xfonts-75dpi wkhtmltopdf
packages: xfonts-base xfonts-75dpi wkhtmltopdf weasyprint
version: ubuntu-24.04

- name: Composer install
Expand All @@ -51,9 +51,9 @@ jobs:
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '8.5' ]]; then
vendor/bin/phpunit --display-warnings --display-deprecations --display-phpunit-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
vendor/bin/phpunit --display-all-issues --fail-on-all-issues --do-not-fail-on-skipped --do-not-fail-on-incomplete --coverage-clover=coverage.xml
else
vendor/bin/phpunit --display-warnings --display-deprecations
vendor/bin/phpunit --display-phpunit-deprecations --display-warnings --display-deprecations
fi

- name: Code Coverage Report
Expand Down
56 changes: 21 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ Engines included in the plugin:
* DomPdf (^3.0)
* Mpdf (^8.0.4)
* Tcpdf (^6.3)
* WkHtmlToPdf **RECOMMENDED ENGINE**
* WeasyPrint (**Recommended** if you have the privileges to install something on your server)
* WkHtmlToPdf (project no longer maintained but binaries still available for various environments)

Community maintained engines:
* [PDFreactor](https://github.com/jmischer/cake-pdfreactor)


## Requirements

* One of the following render engines: DomPdf, Mpdf, Tcpdf or wkhtmltopdf
* One of the following render engines: DomPdf, Mpdf, Tcpdf, WeasyPrint or wkhtmltopdf
* pdftk (optional) See: http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/


## Installation

Using [Composer](http://getcomposer.org):
Expand All @@ -33,7 +32,7 @@ composer require friendsofcake/cakepdf
CakePdf does not include any of the supported PDF engines, you need to install
the ones you intend to use yourself.

Packages for the recommend `wkhtmltopdf` engine can be downloaded from https://wkhtmltopdf.org/downloads.html.
Check [WeasyPrint's](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation) installation guide to install it on your system.
DomPdf, Mpdf and Tcpdf can be installed via composer using one of the following commands:

```
Expand Down Expand Up @@ -74,37 +73,31 @@ pass the config array to constructor. The value for engine should have the
Configuration options:
* engine: Engine to be used (required), or an array of engine config options
* className: Engine class to use
* binary: Binary file to use (Only for wkhtmltopdf)
* cwd: current working directory (Only for wkhtmltopdf)
* binary: Binary file to use (Only for weasyprint/wkhtmltopdf)
* cwd: current working directory (Only for weasyprint/wkhtmltopdf)
* options: Engine specific options. Currently used for following engine:
* `WkHtmlToPdfEngine`: The options are passed as CLI arguments
* `WeasyPrintEngine`: The options are passed as CLI arguments
* `TexToPdfEngine`: The options are passed as CLI arguments
* `DomPdfEngine`: The options are passed to constructor of `Dompdf` class
* `MpdfEngine`: The options are passed to constructor of `Mpdf` class
* crypto: Crypto engine to be used, or an array of crypto config options
* className: Crypto class to use
* binary: Binary file to use
* pageSize: Change the default size, defaults to A4
* orientation: Change the default orientation, defaults to portrait
* margin: Array or margins with the keys: bottom, left, right, top and their values
* title: Title of the document
* delay: A delay in milliseconds to wait before rendering the pdf
* windowStatus: The required window status before rendering the pdf
* pageSize: Change the default size, defaults to A4 (Needs to be set via CSS for WeasyPrint)
* orientation: Change the default orientation, defaults to portrait (Needs to be set via CSS for WeasyPrint)
* margin: Array or margins with the keys: bottom, left, right, top and their values (Needs to be set via CSS for WeasyPrint)
* title: Title of the document (Needs to be set via CSS for WeasyPrint)
* delay: A delay in milliseconds to wait before rendering the pdf (wkhtmltopdf only)
* windowStatus: The required window status before rendering the pdf (wkhtmltopdf only)
* encoding: Change the encoding, defaults to UTF-8
* download: Set to true to force a download, only when using PdfView
* filename: Filename for the document when using forced download

Example:
```php
Configure::write('CakePdf', [
'engine' => 'CakePdf.WkHtmlToPdf',
'margin' => [
'bottom' => 15,
'left' => 50,
'right' => 30,
'top' => 45,
],
'orientation' => 'landscape',
'engine' => 'CakePdf.WeasyPrint',
'download' => true,
]);
```
Expand All @@ -118,13 +111,13 @@ class InvoicesController extends AppController
{
parent::initialize();

// https://book.cakephp.org/5/en/controllers.html#content-type-negotiation
// https://book.cakephp.org/5.x/controllers.html#content-type-negotiation
$this->addViewClasses([PdfView::class]);
}

// In your Invoices controller you could set additional configs,
// or override the global ones:
public function view($id = null)
public function view($id = null): void
{
$invoice = $this->Invoice->get($id);
$this->viewBuilder()->setOption(
Expand All @@ -145,32 +138,25 @@ options for the relevant class. For example:
```php
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'className' => 'CakePdf.WeasyPrint',
// Options usable depend on the engine used.
'options' => [
'print-media-type' => false,
'outline' => true,
'dpi' => 96,
'cover' => [
'url' => 'cover.html',
'enable-smart-shrinking' => true,
],
'toc' => true,
],

/**
* For Mac OS X / Linux by default the `wkhtmltopdf` binary should
* For Mac OS X / Linux by default the `weasyprint` binary should
* be available through environment path or you can specify location as:
*/
// 'binary' => '/usr/local/bin/wkhtmltopdf',
// 'binary' => '/usr/local/bin/weasyprint',

/**
* On Windows the engine uses the path shown below as default.
* You NEED to use the path like old fashioned MS-DOS Paths,
* otherwise you will get error like:
* "WKHTMLTOPDF didn't return any data"
* "weasyprint didn't return any data"
*/
// 'binary' => 'C:\\Progra~1\\wkhtmltopdf\\bin\\wkhtmltopdf.exe',
// 'binary' => 'C:/Progra~1/WeasyPrint/bin/weasyprint.exe',
],
]);
```
Expand Down
58 changes: 1 addition & 57 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="6.0.0@b8e96bb617bf59382113b1b56cef751f648a7dc9">
<files psalm-version="6.15.1@28dc127af1b5aecd52314f6f645bafc10d0e11f9">
<file src="src/Pdf/CakePdf.php">
<InvalidDocblock>
<code><![CDATA[public function cache(bool|string|null $cache = null): static|string|false]]></code>
<code><![CDATA[public function delay(?int $delay = null): static|int|null]]></code>
<code><![CDATA[public function encoding(?string $encoding = null): static|string]]></code>
<code><![CDATA[public function footer(string|array|null $left = null, ?string $center = null, ?string $right = null): static|array]]></code>
<code><![CDATA[public function header(string|array|null $left = null, ?string $center = null, ?string $right = null): static|array]]></code>
<code><![CDATA[public function helpers(?array $helpers = null): static|array]]></code>
<code><![CDATA[public function html(?string $html = null): static|string]]></code>
<code><![CDATA[public function layoutPath(?string $layoutPath = null): static|string]]></code>
Expand All @@ -29,59 +27,5 @@
<code><![CDATA[public function viewVars(?array $viewVars = null): static|array]]></code>
<code><![CDATA[public function windowStatus(?string $status = null): static|string|null]]></code>
</InvalidDocblock>
<PossiblyInvalidArgument>
<code><![CDATA[$cache]]></code>
<code><![CDATA[$cache]]></code>
<code><![CDATA[$cache]]></code>
<code><![CDATA[$viewClass]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidPropertyAssignmentValue>
<code><![CDATA[$cache]]></code>
<code><![CDATA[$permissions]]></code>
</PossiblyInvalidPropertyAssignmentValue>
</file>
<file src="src/Pdf/Crypto/PdftkCrypto.php">
<PossiblyInvalidArgument>
<code><![CDATA[$ownerPassword]]></code>
<code><![CDATA[$userPassword]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Pdf/Engine/DomPdfEngine.php">
<PossiblyInvalidArgument>
<code><![CDATA[$Pdf->html()]]></code>
<code><![CDATA[$this->_Pdf->orientation()]]></code>
<code><![CDATA[$this->_Pdf->pageSize()]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Pdf/Engine/MpdfEngine.php">
<PossiblyInvalidArgument>
<code><![CDATA[$format]]></code>
<code><![CDATA[$this->_Pdf->html()]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidOperand>
<code><![CDATA[$format]]></code>
</PossiblyInvalidOperand>
</file>
<file src="src/Pdf/Engine/TcpdfEngine.php">
<PossiblyInvalidArgument>
<code><![CDATA[$this->_Pdf->html()]]></code>
<code><![CDATA[$this->_Pdf->orientation()]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Pdf/Engine/TexToPdfEngine.php">
<PossiblyInvalidArgument>
<code><![CDATA[$output]]></code>
<code><![CDATA[$output]]></code>
<code><![CDATA[$this->_Pdf->encoding()]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Pdf/Engine/WkHtmlToPdfEngine.php">
<PossibleRawObjectIteration>
<code><![CDATA[$margin]]></code>
</PossibleRawObjectIteration>
<PossiblyInvalidArgument>
<code><![CDATA[$this->_Pdf->html()]]></code>
<code><![CDATA[$value]]></code>
</PossiblyInvalidArgument>
</file>
</files>
20 changes: 2 additions & 18 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
autoloader="tests/bootstrap.php"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -16,24 +17,7 @@
</ignoreFiles>
</projectFiles>

<stubs>
<file name="vendor/cakephp/cakephp/src/Core/Exception/CakeException.php" preloadClasses="true" />
</stubs>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />

<UnsafeInstantiation errorLevel="info" />
<RiskyTruthyFalsyComparison errorLevel="info" />
<MissingOverrideAttribute errorLevel="info" />
</issueHandlers>
</psalm>
Loading
Loading