pdftoolkit / pdf-to-html
Object-oriented tagged PDF to semantic HTML derivation following PDF Association Deriving HTML 1.2 for PHP 8.3+
Requires
- php: ^8.3
- php-64bit: *
- ext-dom: *
- ext-mbstring: *
- pdftoolkit/pdf-reader: ^0.2.1
- roukmoute/pdf: ^0.7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-10-14 20:52:16 UTC
README
Derive semantic HTML from tagged PDF using explicit PHP objects, following Deriving HTML from PDF 1.2 (PDF Association, September 2026).
This repository was created specifically to implement the rules in Deriving_HTML_from_PDF_1-2.pdf. The current implementation is partial. The coverage guide records tested mechanisms and the technical work that remains.
This optional package keeps derivation outside the PDF core. It exploits logical structure and Unicode content rather than guessing reading order from character positions. It does not reproduce page layout or promise conversion of every PDF.
Install
composer require "pdftoolkit/pdf-to-html:^0.1.2"
Requires 64-bit PHP 8.3+ with DOM and mbstring. CI checks PHP 8.3, 8.4 and 8.5. Composer installs the PDF core and reader as dependencies; installing the core alone does not install this module.
Read, derive, then write
The application supplies bytes and chooses where to write the result. Reading, semantic derivation and filesystem operations remain separate:
use PDF\Html\HtmlDeriver; use PDF\Html\Reading\ReadPdfSource; use PDF\Reading\DocumentReader; use PDF\Reading\FileBytes; $document = (new DocumentReader())->read(new FileBytes($pdfBytes)); $source = (new ReadPdfSource())->read($document, 'document.pdf'); $result = (new HtmlDeriver())->derive($source); $html = $result->html;
PdfToHtml can coordinate these same stages without hiding file access:
$result = (new \PDF\Html\PdfToHtml())->convert( new FileBytes($pdfBytes), 'document.pdf', );
Its constructor accepts the reader, source adapter, deriver and an optional authentication provider as explicit objects. Conversion still receives bytes; the source filename is descriptive and is not opened implicitly.
DerivationResult returns HTML, CSS, assets and diagnostics explicitly. Inspect
them before publishing the result. Write every asset beside the HTML, using its
returned filename, or remap its URLs consistently. When trusted scripts are
enabled, ScriptAssetEmitter returns external pdf-script-<sha256>.js files;
the HTML depends on those files. The immutable source model can also be built
directly by an application, independently of file parsing.
Run the real PDF example:
php examples/01-derive-tagged-pdf.php tests/Fixtures/tagged.pdf _build/derived.html
The script receives explicit input/output paths, writes HTML and every returned asset to the output directory, and prints hashes and diagnostics as JSON. The central tutorial provides the input PDF, rendered pages, executable PHP and actual HTML result.
Understand the boundaries
- Architecture: source objects, roles and serialization.
- Coverage: reference scope and file-adapter boundaries.
- Security: budgets, HTML/CSS/URL validation and active content.
- Retained reference: original PDF, license and fingerprint.
- Complete API and guides.
The library does not execute scripts or implicitly fetch external resources. The reference's ECMAScript rules must be read alongside the explicit security policy, not as a promise to emulate Acrobat's JavaScript API. Semantic HTML does not certify accessibility or PDF/UA.
Develop
composer install composer check
Follow the release procedure for exact-candidate CI, independent validation and stable-consumer verification. Code is MIT licensed; the retained PDF Association publication has its own CC-BY-4.0 license.