Download the PHP package paperdoc-dev/paperdoc-lib without Composer
On this page you can find all versions of the php package paperdoc-dev/paperdoc-lib. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package paperdoc-lib
Paperdoc Library
A zero-dependency PHP library for generating, parsing and converting documents — PDF, HTML, CSV, DOCX, XLSX, PPTX, Markdown and more.
Features
- Generate documents from scratch (PDF, HTML, CSV, DOCX, XLSX, PPTX, Markdown)
- Parse existing documents into a unified in-memory model
- Convert between any supported formats in one call
- Rich document model — typed headings, ordered/bullet lists (nested), bookmarks, code blocks, blockquotes, images, tables, page breaks and typed document properties (author, subject, dates…)
- Per-page layout (v0.7.0+) — per-section
PageSetupwith custom size (or anyPageSizeenum), padding, full-page background image (cover/contain/auto/stretchsince v0.7.1) or color ; absolutely-positionedTextZoneblocks withclip/ellipsis/visibleoverflow strategies and per-paragraph alignment (left/center/right/justify, v0.7.1) ; document-wide running headers / footers with{page}/{pages}/{title}/{date}/{datetime}placeholders - Typographic quality (v0.7.3) — per-glyph metrics from the 14 standard PDF fonts (Core 14, AFM-derived) so centering, right-alignment, justification and word-wrapping are pixel-accurate ; ascent-aware vertical stacking (no more eyebrow/title overlap) ; justification combines
Tw(word-spacing) andTc(character-spacing) and falls back to flush-left when a line would produce visible "rivers" - Layout & typography APIs (v0.8.0) — per-section header/footer override (
Section::setHeader/setFooter/hideHeader/hideFooter) ;Section::setVerticalAlignment(TOP/CENTER/BOTTOM)for chapter openers / colophons ; per-side padding shortcuts (setPagePaddingTop/Right/Bottom/Left) ;ParagraphStyle::setFirstLineIndent()(CSStext-indent) ;TextStyle::setLetterSpacing()(PDFTcoperator, HTMLletter-spacing) ; newHorizontalRuleblock element rendered to PDF (stroked line), HTML (<hr>), Markdown (---) and DOCX (bordered paragraph) - Native rendering core — every block element renders cleanly to DOCX, PDF, HTML and Markdown: typed headings (
<h1>/<w:pStyle>), nested lists (<ul>/<w:numPr>), blockquotes, code blocks (with language hint), bookmarks, embedded or on-disk images - Hyperlinks — parse
<w:hyperlink>from DOCX and round-trip them to HTML<a>, Markdown[text](url)and DOCX hyperlink relationships, with anchors and tooltips - Batch processing — open and process multiple files at once
- Laravel integration — first-class ServiceProvider and Facade
- AI-powered features via Neuron AI (OCR, LLM extraction)
- Typed exceptions —
ParserException,RendererException,UnsupportedFormatException,InvalidDocumentExceptionall extending a commonPaperdocException - Zero native binary dependencies — pure PHP
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.2 |
| ext-dom | * |
| ext-mbstring | * |
| ext-zip | * |
| ext-zlib | * |
Optional (Laravel)
| Package | Version |
|---|---|
| illuminate/support | ^11.0 | ^12.0 |
Installation
Laravel auto-discovery
The PaperdocServiceProvider and Paperdoc facade are registered automatically via Laravel's package auto-discovery.
Quick Start
DocumentManager uses static methods (create, save, open, …). A document is built from Section instances: use addSection($section) or addSection() to append an empty section, or openSection() when you want a fluent chain (addParagraph, addHeading, …) on the new section. Bold and other run styles live on TextStyle. For advanced layouts (custom page size, full-page backgrounds, absolutely-positioned text zones, running headers/footers), see Page layout below.
Standalone PHP
Laravel (via Facade)
Supported Formats
| Format | Parse | Render/Generate |
|---|---|---|
| ✅ | ✅ | |
| HTML | ✅ | ✅ |
| DOCX | ✅ | ✅ |
| XLSX | ✅ | ✅ |
| PPTX | ✅ | ✅ |
| CSV | ✅ | ✅ |
| Markdown | ✅ | ✅ |
| DOC | ✅ | ✅ |
| XLS | ✅ | ✅ |
| PPT | ✅ | ✅ |
Document Model
Every format shares the same strongly-typed in-memory structure:
All block elements implement Paperdoc\Contracts\BlockElementInterface. Styles live in Document/Style/ (ParagraphStyle, TextStyle, TableStyle), links in Document/Link/TextLink, typed document properties in Document/Metadata.
Example — build a richly-typed document
Page layout, text zones, headers & footers
Available since v0.7.0. Each section can declare its own page
geometry through a PageSetup value object, and place
absolutely-positioned TextZone blocks anywhere on the page. Combine
several sections (each with its own PageSetup) to build documents
where every page has a different size and background. Add a global
RunningElement to the Document to draw a header/footer on every
page.
Configure a page
Section exposes shortcut setters (setPageSize(),
setPageDimensions(), setPagePadding(),
setPageBackgroundImage(), setPageBackgroundColor()) that delegate
to a lazily-created PageSetup.
| Setter / Factory | Purpose |
|---|---|
PageSetup::fromSize(PageSize, $orientation = 'portrait') |
Use a standard format (A3/A4/A5/A6/Letter/Legal/Tabloid/Executive) |
PageSetup::custom($width, $height) |
Any dimensions in PDF points |
landscape() / portrait() |
Flip the active orientation |
setPadding(...) (1–4 values) |
CSS-style shorthand for top/right/bottom/left padding |
setBackgroundColor($hex) |
Solid full-bleed background color |
setBackgroundImage(Image) |
Full-bleed image (on-disk or Image::fromData()) |
setBackgroundSize(string) (v0.7.1) |
cover (default), contain, auto, stretch (=100% 100%), or any CSS string |
setBackgroundPosition(string) (v0.7.1) |
CSS string, default 'center center' |
setBackgroundRepeat(string) (v0.7.1) |
CSS string, default 'no-repeat' |
Fit the background image — cover / contain / auto / stretch
Available since v0.7.1. Both renderers (PDF and HTML) honour the
same four CSS-like modes. cover and auto automatically clip the
overflow with a clip path in the PDF and overflow: hidden in the HTML
output.
BG_SIZE_* constant |
CSS equivalent | Behaviour |
|---|---|---|
BG_SIZE_COVER |
cover |
Fills the page, preserves aspect ratio, overflow is clipped (default) |
BG_SIZE_CONTAIN |
contain |
Fits inside the page, preserves aspect ratio (may leave empty bands) |
BG_SIZE_AUTO |
auto |
Image at its natural size, centred, clipped if larger than the page |
BG_SIZE_STRETCH |
100% 100% |
Stretches to fill the page; aspect ratio is not preserved (legacy mode) |
Any other CSS-valid string ('50% auto', '300pt 200pt', …) is
accepted as-is in HTML output.
Place text precisely with TextZone
| Overflow strategy | Behaviour |
|---|---|
TextZone::OVERFLOW_CLIP |
(Default) Silently truncates content that doesn't fit |
TextZone::OVERFLOW_ELLIPSIS |
Truncates and ends the last visible line with … (PDF: native; HTML: pseudo-element) |
TextZone::OVERFLOW_VISIBLE |
No clipping — content may flow outside the box (kept for parity with CSS) |
Coordinates use the top-left convention (x=0, y=0 is the top-left
of the page) for both PDF and HTML — the PdfRenderer flips to PDF's
bottom-left origin internally.
Per-paragraph alignment inside a zone — v0.7.1
Each paragraph of a TextZone carries its own ParagraphStyle, so
you can mix several alignments in the same zone (centred title,
justified body, right-aligned signature, …):
In the PDF, justification is implemented with the native PDF
word-spacing operator (Tw); the last line of a paragraph is
intentionally left-aligned to avoid stretched short lines.
Document-wide headers and footers
Supported placeholders in the template: {page} (1-indexed current
page), {pages} (total pages), {title} (the document title),
{date} (Y-m-d) and {datetime} (Y-m-d H:i). The renderer
resolves them per page so you don't need to update the template
between pages.
The HTML renderer adds a translucent rgba(255, 255, 255, 0.85)
backdrop with a backdrop-filter: blur(2px) behind the running
elements so they remain legible on top of any background image. The
library does not automatically reserve vertical space for the
header/footer — keep that in mind when positioning a TextZone close
to a page edge.
Per-section header / footer override (v0.8.0)
A document-level header/footer applies uniformly to every page by default. Often that's not what you want — a cover page should NOT carry the page-number footer (it would either disappear under the artwork or fight with the imagery for legibility), and a colophon on the last page might want a different label. Since v0.8.0, sections can override or suppress the document-level running elements:
Resolution rule — for every page, the renderer picks (in order) :
- If
Section::hideHeader()/hideFooter()was called → no header/footer is drawn. - If
Section::setHeader()/setFooter()was called with a non-null element → that element is drawn. - Otherwise → the document-level header/footer is drawn (if any).
Both PDF and HTML renderers honour this resolution.
Vertical alignment of section content (v0.8.0)
By default the content of a section flows from the top padding downwards. For pages that should breathe vertically — chapter openers, colophons, frontispieces, single-paragraph "blank" pages — you can centre or bottom-anchor the content :
Implementation notes :
- The PDF renderer captures the section's content slice, measures
its rendered height, then wraps it in a native PDF
q ... 1 0 0 1 0 dy cm ... Qtranslation block — no overhead, no pre-render measurement pass. - The HTML renderer applies the same semantics via flexbox
(
display:flex; justify-content:centerforCENTER,flex-endforBOTTOM). - Sections that overflow onto a second page automatically fall back to TOP alignment to avoid a stale CTM bleeding across pages. If you need centring on a section with lots of content, reduce its content first.
Per-side padding shortcuts (v0.8.0)
Section::setPagePadding(...$values) already accepts CSS-shorthand
1-/2-/3-/4-value forms. When only ONE side needs tweaking — typical
for a frontispiece title that should sit ~110pt from the top — the
new per-side shortcuts are clearer :
Available : setPagePaddingTop(), setPagePaddingRight(),
setPagePaddingBottom(), setPagePaddingLeft(). They all return
$this for chaining.
First-line indent and letter-spacing (v0.8.0)
Two style-level additions that previously had to be hacked at the application layer :
Paragraph first-line indent
ParagraphStyle::setFirstLineIndent(float $points) mirrors the CSS
text-indent property : only the first line of the paragraph
starts further to the right. Negative values produce a hanging
indent (first line jutting OUT to the left of the block — a
typographic device used in lists or dictionary entries).
The PDF wrap engine sees a tighter budget for the first line so
wrapping accounts for the indent correctly. The HTML renderer
emits text-indent: Xpt on the paragraph's inline style.
Run letter-spacing
TextStyle::setLetterSpacing(float $points) opens out a run of
text by the requested number of points between every pair of
adjacent glyphs. Common uses : an opened-out section heading
(setLetterSpacing(1.5)), or marking an acronym in small-caps
style. Negative values pull glyphs closer.
PDF emits the native Tc operator and resets to 0 after the run,
so copy-paste from the rendered file gives back the original
(un-spaced) text — a property the previous "insert thin spaces
between every glyph" workarounds did not have. HTML emits
letter-spacing: Xpt. measureTextWidth() and wrapText()
correctly account for letter-spacing.
Horizontal rule (v0.8.0)
A first-class block element for visual separators :
| Property | Type | Default | Notes |
|---|---|---|---|
width |
string\|float |
'100%' |
Either a CSS-style percentage ('50%') or absolute pt. |
thickness |
float (pt) |
0.5 |
Word-style "thin rule" by default. |
color |
string hex |
'#999999' |
CSS hex (#rgb or #rrggbb). |
alignment |
Alignment |
CENTER |
LEFT / CENTER / RIGHT for partial-width rules. |
marginTop |
float (pt) |
6.0 |
Vertical breathing space above the rule. |
marginBottom |
float (pt) |
6.0 |
Below. |
Renderers :
- PDF : a stroked horizontal line, drawn with the requested thickness and stroke colour.
- HTML :
<hr>with inline CSS (border-top:Wpt solid C ; width:X ; margin:T 0 B). - Markdown :
---thematic break (CommonMark). - DOCX : the canonical Word "horizontal line" — an empty
paragraph carrying a
<w:pBdr><w:bottom .../></w:pBdr>with the requested colour and thickness in eighths-of-a-point.
Rendering
Since v0.5.0, every element of the document model is natively rendered by all four core renderers — no element is silently dropped, every output is a valid file format.
| Element | DOCX | HTML | Markdown | |
|---|---|---|---|---|
Heading (1–6) |
<w:pStyle w:val="HeadingN"/> + bookmark anchor |
typed font sizes (24/20/16/14/13/12 pt) + navy | <h1>…<h6> with id |
#…######, optional {#id} |
Paragraph |
<w:p> + run styling |
wrapped text + inline run styles | <p> + inline <span> |
plain text + emphasis |
ListBlock |
<w:numPr> + word/numbering.xml, nested <w:ilvl> |
• / 1. markers, depth-based indent |
<ul> / <ol start="N">, nested |
- / 1., two-space indent |
Blockquote |
<w:pStyle w:val="Quote"/> + indent |
indented italic muted-grey | <blockquote> (nested children) |
> prefixed lines |
CodeBlock |
<w:pStyle w:val="Code"/> + Consolas + <w:br/> |
Courier, dedicated spacing | <pre><code class="language-…"> |
fenced ` bash |
php artisan vendor:publish --tag=paperdoc-config bash composer test
or
./vendor/bin/phpunit
src/ ├── Concerns/ # Shared traits ├── Console/ # Artisan commands ├── Contracts/ # DocumentInterface, ParserInterface, BlockElementInterface… ├── Document/ # Core model (Document, Section, Paragraph, Heading, ListBlock, Bookmark, CodeBlock, Blockquote, Metadata…) ├── Enum/ # Format enums ├── Exceptions/ # PaperdocException + typed exceptions ├── Facades/ # Laravel Facade ├── Factory/ # Document/Parser factories ├── Llm/ # AI/LLM integration (Neuron AI) ├── Ocr/ # OCR integration ├── Parsers/ # Format-specific parsers ├── Renderers/ # Format-specific renderers ├── Support/ # DocumentManager and helpers └── PaperdocServiceProvider.php
---
## Contributing
We welcome contributions! Please read [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request.
### Contributors
Thanks to everyone who has contributed to **paperdoc-lib**. A full list is kept in [CONTRIBUTORS.md](CONTRIBUTORS.md).
- **Olivier Mourlevat** — [@olivM](https://github.com/olivM) — DOCX hyperlink parsing, HTML/Markdown hyperlink rendering ([#4](https://github.com/paperdoc-dev/paperdoc-lib/pull/4))
---
## Changelog
See [CHANGELOG.md](CHANGELOG.md) for release history.
---
## License
Paperdoc Library is released under the **[MIT License](LICENSE)** — free to use, modify and distribute, commercial or not.
© Paperdoc — [paperdoc.dev](https://paperdoc.dev)All versions of paperdoc-lib with dependencies
ext-dom Version *
ext-mbstring Version *
ext-zip Version *
ext-zlib Version *
neuron-core/neuron-ai Version ^3.0