PHPackages                             vielhuber/pdfexport - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vielhuber/pdfexport

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vielhuber/pdfexport
===================

Collection of useful shorthand string related functions in php.

1.5.6(3w ago)212.0k↓22.5%1MITPHPPHP &gt;=7.4

Since Mar 23Pushed 3w ago1 watchersCompare

[ Source](https://github.com/vielhuber/pdfexport)[ Packagist](https://packagist.org/packages/vielhuber/pdfexport)[ RSS](/packages/vielhuber-pdfexport/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (5)Versions (58)Used By (0)

[![build status](https://github.com/vielhuber/pdfexport/actions/workflows/ci.yml/badge.svg)](https://github.com/vielhuber/pdfexport/actions)[![GitHub Tag](https://camo.githubusercontent.com/c843c076d9487d3141675b6a136025a4580a2fc9832325adec20b689eb2c32cb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f7669656c68756265722f7064666578706f7274)](https://github.com/vielhuber/pdfexport/tags)[![Code Style](https://camo.githubusercontent.com/1540f8ce219727155ab62506c77b818b720421c22c4cf0b18a5f160942132e2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64655f7374796c652d7073722d2d31322d6666363962342e737667)](https://www.php-fig.org/psr/psr-12/)[![License](https://camo.githubusercontent.com/de35577fe90f81694a35be4aa8bba8caba3ffb67b008da0bb516bc6597d526ad/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7669656c68756265722f7064666578706f7274)](https://github.com/vielhuber/pdfexport/blob/main/LICENSE.md)[![Last Commit](https://camo.githubusercontent.com/125d06080b3a7282a57bebafb26e2c1a0e314bdade051fe3f8829c9066c0a3fa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7669656c68756265722f7064666578706f7274)](https://github.com/vielhuber/pdfexport/commits)[![PHP Version Support](https://camo.githubusercontent.com/a83ab61f9506ea2a9f522cf5f27fc168ca758a59a5e6624733f5aa7c6219c6d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7669656c68756265722f7064666578706f7274)](https://packagist.org/packages/vielhuber/pdfexport)[![Packagist Downloads](https://camo.githubusercontent.com/a5d94f4ddfaf38be185c5bb110d5071160e47de0f559c0c004f69c7331a9e8b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7669656c68756265722f7064666578706f7274)](https://packagist.org/packages/vielhuber/pdfexport)

🍊 pdfexport 🍊
=============

[](#-pdfexport-)

pdfexport is a powerful php library for pdf generation and manipulation. it combines proven tools like wkhtmltopdf, pdftk, ghostscript and cpdf under a unified, user-friendly api. whether you want to convert html documents to pdfs, merge existing pdfs, fill out forms or add watermarks – pdfexport makes it easy and performant.

Features
--------

[](#features)

- easy syntax
- can merge/grayscale/fill pdfs
- individual headers per page possible
- very fast because of combining commands
- overcomes command line / process limits
- allows php code inside html templates
- counts pages of pdfs
- can set a limit on page counts
- splits pdfs in chunks of size n
- can create pdf/a files
- can disallow printing and editing
- stamp/watermark pdfs

Requirements
------------

[](#requirements)

- [pdftk](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/)
- [wkhtmltopdf](https://wkhtmltopdf.org/)
- [ghostscript](https://www.ghostscript.com/)
- [imagemagick](https://www.imagemagick.org/)
- [cpdf](http://community.coherentpdf.com/)

Installation
------------

[](#installation)

install once with [composer](https://getcomposer.org/):

```
composer require vielhuber/pdfexport

```

then add this to your files:

```
require __DIR__ . '/vendor/autoload.php';
use vielhuber\pdfexport\pdfexport;
```

you also can provide custom paths to underlying libs:

```
$_ENV['PDFTK'] = 'C:\pdftk\bin\pdftk.exe';
$_ENV['WKHTMLTOPDF'] = 'C:\wkhtmltopdf\bin\wkhtmltopdf.exe';
$_ENV['GHOSTSCRIPT'] = 'C:\Program Files\GS\gs9.22\bin\gswin64c.exe';
$_ENV['IMAGEMAGICK'] = 'C:\Program Files\ImageMagick-6.9.9-Q16\convert.exe';
$_ENV['CPDF'] = 'C:\Program Files\cpdf\cpdf.exe';
```

in [laravel](https://www.laravel.org) just populate .env:

```
PDFTK="C:\pdftk\bin\pdftk.exe"
WKHTMLTOPDF="C:\wkhtmltopdf\bin\wkhtmltopdf.exe"
GHOSTSCRIPT="C:\Program Files\GS\gs9.22\bin\gswin64c.exe"
IMAGEMAGICK="C:\Program Files\ImageMagick-6.9.9-Q16\convert.exe"
CPDF="C:\Program Files\cpdf\cpdf.exe"
```

and can overcome \*nix limits by increasing the ulimit for open files:

```
ulimit -n 999999

```

you can do this permanently inside /etc/security/limits.conf:

```
* - nofile 999999

```

Usage
-----

[](#usage)

```
$pdf = new pdfexport;

// add a static pdf
$pdf->add('tests/file.pdf');

// add a static pdf and fill out the form
$pdf->add('tests/file.pdf')
    ->data([
        'placeholder1' => 'foo',
        'placeholder2' => 'bar'
    ]);

// add multiple portions of data
$pdf->add('tests/file.pdf')
    ->data([
        'placeholder1' => 'This is a test',
        'placeholder2' => 'This is a multiline\ntest1\ntest2\ntest3\ntest4\ntest5\ntest6\ntest7\ntest8\ntest9\ntest10'
    ])
    ->data([
        'placeholder3' => 'This is Sonderzeichen ß täst!'
    ]);

// form fields
$pdf->getFormFields('tests/file.pdf'); // [ ['name' => 'field_name_1', 'type' => 'Text'], ... ]
$pdf->hasFormField('tests/file.pdf', 'field_name_1') // true

// do the same but grayscale the page
$pdf->add('tests/file.pdf')
    ->grayscale();

// grayscale (not vector) with a resolution of 80%
$pdf->add('tests/file.pdf')
    ->grayscale(80);

// add a html file
$pdf->add('tests/file.html');

// add a html file in a3, landscape
$pdf->add('tests/file.html')
    ->format('a3','landscape');

// add a html file with custom margins in mm
$pdf->add('tests/file.html')
    ->margin(10, 10, 17, 17);

// add a html file with wkhtmltopdf smart shrinking enabled
$pdf->add('tests/file.html')
    ->smartShrinking();

// add a html file and replace placeholders ()
$pdf->add('tests/file.html')
    ->data([
        'placeholder1' => 'foo',
        'placeholder2' => 'bar'
    ]);

// add a html file with a header and footer with a height of 30mm (there also can be placeholders in the header/footer)
$pdf->add('tests/file.html')
    ->header('tests/header.html', 30)
    ->footer('tests/footer.html', 30)
    ->data([
        'placeholder1' => 'foo',
        'placeholder2' => 'bar'
    ]);

// strings are interpreted as html code
$pdf->add('body with ')
    ->header('header with ')
    ->footer('footer with ')
    ->data([
        'placeholder1' => 'foo',
        'placeholder2' => 'bar',
        'placeholder3' => 'baz'
    ]);

// you can also execute php code inside templates
$pdf->add('cur time:
