Lpdf PHP SDK: render PDF documents from XML or from code.
With data binding, PDF/A, PDF/UA, PDF/X and Factur-X / ZUGFeRD.
composer require lpdfio/lpdfuse Lpdf\L;
use Lpdf\Kit\DocumentAttr;
use Lpdf\Kit\LayoutAttr;
use Lpdf\Layout\ColumnAttr;
use Lpdf\Layout\DividerAttr;
use Lpdf\Layout\RowAttr;
use Lpdf\Layout\TextAttr;
use const Lpdf\NoAttr;
$engine = L::engine();
$doc = L::document(new DocumentAttr(size: 'Letter'), [
L::section(NoAttr, [
L::layout(new LayoutAttr(margin: '48pt'), [
L::column(new ColumnAttr(gap: '24pt'), [
L::row(new RowAttr(justify: 'between'), [
L::text(new TextAttr(fontSize: '8pt', color: '#888888'), ['ACME CORP']),
L::text(new TextAttr(fontSize: '22pt', bold: true), ['Project Proposal']),
]),
L::divider(new DividerAttr(thickness: 'xs')),
L::text(new TextAttr(fontSize: '13pt', bold: true), ['Scope of Work']),
L::row(new RowAttr(gap: '12pt', align: 'start'), [
L::text(new TextAttr(color: '#888888', width: '24pt'), ['01']),
L::text(new TextAttr(width: 'fill'), ['Discovery & Research']),
]),
]),
]),
]),
]);
$pdf = $engine->render($doc);- PHP 8.2 or later, with the DOM extension (
ext-dom; on Debian and Ubuntu it is thephp-xmlpackage) - One of the two ways the SDK runs the engine, which it picks itself (How PHP runs the engine):
- The native library in the package, through PHP's FFI extension (
ext-ffi): on Linux with glibc 2.17 or newer, on x86_64 or arm64. A web server needsffi.enable=truein php.ini; the command line allows FFI as it is. - The
wasmtimecommand-line tool on yourPATH, which runs the bundled WASI binary: everywhere else, such as macOS, Windows and Alpine, and where FFI isn't allowed. On Linux and macOS, where PHP's user can't write its home, aswww-dataunder PHP-FPM, it also needs PHP's POSIX extension (ext-posix), for the SDK's cache folder.
- The native library in the package, through PHP's FFI extension (
Report bugs and request features at github.com/lpdfio/lpdf/issues, the one tracker for the engine, the SDKs and the VS Code extension. Pull requests are not accepted.
Licensed under the Lpdf License. See LICENSE for full terms.