Skip to content
lpdfioPublic

About

Lpdf PHP SDK: render PDF documents from XML or from code. With data binding, PDF/A, PDF/UA, PDF/X and Factur-X / ZUGFeRD.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Lpdf - PDF as Code

Lpdf PHP SDK: render PDF documents from XML or from code.

With data binding, PDF/A, PDF/UA, PDF/X and Factur-X / ZUGFeRD.

Installation

composer require lpdfio/lpdf

Usage

use 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);

Requirements

  • PHP 8.2 or later, with the DOM extension (ext-dom; on Debian and Ubuntu it is the php-xml package)
  • 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 needs ffi.enable=true in php.ini; the command line allows FFI as it is.
    • The wasmtime command-line tool on your PATH, 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, as www-data under PHP-FPM, it also needs PHP's POSIX extension (ext-posix), for the SDK's cache folder.

Docs

lpdf.io/docs

Issues

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.

About

Lpdf PHP SDK: render PDF documents from XML or from code. With data binding, PDF/A, PDF/UA, PDF/X and Factur-X / ZUGFeRD.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages