|
3 | 3 |
|
4 | 4 | # xobject-template |
5 | 5 |
|
6 | | -> Compile a minimal HTML+CSS subset into reusable PDF Form XObject templates for visible signatures. |
| 6 | +> Compile a minimal HTML+CSS subset into reusable PDF Form XObject payloads. |
7 | 7 |
|
8 | | -`xobject-template` is a focused rendering engine for digital-signature ecosystems that need **beautiful, vector-first, stable** appearance templates with predictable performance. |
| 8 | +`xobject-template` is a focused rendering engine for projects that need **beautiful, vector-first, stable** reusable overlays inside PDF workflows. |
9 | 9 |
|
10 | 10 | ## Why this package |
11 | 11 |
|
12 | | -- Product-ready visible signature templates (text + image) as real XObject payloads |
13 | | -- Clean integration path for `pdf-signer-php` and LibreSign-like platforms |
| 12 | +- Reusable XObject payloads for labels, stamps, approvals, and other document overlays |
| 13 | +- Clean integration path for any PDF pipeline that can embed Form XObjects |
14 | 14 | - Lean API designed for long-term compatibility and monetizable maintainability |
15 | 15 |
|
16 | 16 | ## Quick integration |
17 | 17 |
|
18 | | -Use the compiler to generate `content stream`, `resources`, and `bbox`, then map the output to your signature appearance DTO adapter. |
| 18 | +Use the compiler to generate a reusable XObject result. Consumers that prefer arrays over DTOs can adapt the result into a generic payload shape. |
| 19 | + |
| 20 | +```php |
| 21 | +use LibreSign\XObjectTemplate\Dto\CompileRequest; |
| 22 | +use LibreSign\XObjectTemplate\Integration\XObjectPayloadAdapter; |
| 23 | +use LibreSign\XObjectTemplate\XObjectTemplateCompiler; |
| 24 | + |
| 25 | +$compiler = new XObjectTemplateCompiler(); |
| 26 | + |
| 27 | +$result = $compiler->compile(new CompileRequest( |
| 28 | + html: '<div style="font-size:10px;color:#111111">Rendered for Alice</div>' |
| 29 | + . '<img src="/tmp/example-image.png" style="width:24px;height:24px" />', |
| 30 | + width: 240.0, |
| 31 | + height: 84.0, |
| 32 | +)); |
| 33 | + |
| 34 | +$payload = (new XObjectPayloadAdapter())->toXObjectPayload($result); |
| 35 | +``` |
| 36 | + |
| 37 | +### Output contract |
| 38 | + |
| 39 | +- `$result->contentStream`: PDF operators ready for a Form XObject stream |
| 40 | +- `$result->resources`: font/image resource dictionary keyed for PDF serialization |
| 41 | +- `$result->bbox`: bounding box as `[x1, y1, x2, y2]` |
| 42 | +- `$result->metadata`: render diagnostics such as `line_count`, `image_count`, `node_count`, and `render_ms` |
| 43 | +- `$payload`: transport-agnostic array with `stream`, `resources`, and `bbox` |
| 44 | + |
| 45 | +## Supported HTML/CSS subset |
| 46 | + |
| 47 | +### HTML |
| 48 | + |
| 49 | +- Supported elements: `<div>`, `<p>`, `<span>`, `<br>`, `<img>` |
| 50 | +- Text fragments are normalized into inline text nodes internally |
| 51 | +- Inline styles are read from the `style` attribute |
| 52 | +- Images use the `src` attribute as the source reference included in the resource dictionary |
| 53 | + |
| 54 | +### CSS used by the renderer |
| 55 | + |
| 56 | +- Typography: `font-size`, `font-family`, `font-weight`, `line-height`, `color` |
| 57 | +- Layout: `margin`, `padding`, `text-align`, `width`, `height` |
| 58 | +- Numeric values can be provided as unitless numbers or `px` |
| 59 | +- `px` values are converted to PDF points using the package conversion rules |
| 60 | +- Unknown or incomplete CSS declarations are ignored instead of aborting the render |
| 61 | + |
| 62 | +### Rendering notes |
| 63 | + |
| 64 | +- Font family mapping currently targets the built-in Helvetica, Times, and Courier aliases used by the generated PDF resources |
| 65 | +- `img` width/height fall back to `32x32` when omitted or invalid |
| 66 | +- Image and text placement are clamped to the requested output box |
| 67 | +- The compiler output is not tied to any single downstream package; any consumer that understands Form XObject stream/resources/bbox data can use it |
| 68 | + |
| 69 | +## Failure modes |
| 70 | + |
| 71 | +- Unsupported HTML elements raise `UnsupportedSubsetException` |
| 72 | +- Malformed HTML fragments are normalized by `DOMDocument` before traversal |
| 73 | +- Empty text nodes and invalid inline-style fragments are ignored during parsing/rendering |
0 commit comments