papercut / docx
Word (.docx) export for Papercut documents.
Requires
- php: ^8.4
- ext-zip: *
- dskripchenko/php-docx: ^1.18
- papercut/core: ^0.9
Requires (Dev)
- bacon/bacon-qr-code: ^3.1
- phiki/phiki: ^2.2
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
Suggests
- ext-gd: Pictures in Word: WebP and AVIF images, image cover and opacity, and plain QR codes
- ext-imagick: Styled QR codes and SVG in Word (SVG needs an Imagick build that reads SVG)
- bacon/bacon-qr-code: Styled QR codes (with ext-imagick)
Provides
None
Conflicts
None
Replaces
None
README
papercut/docx
Word (.docx) export for Papercut documents: the same document you render as a PDF, as a file people can open and edit in Word, LibreOffice or Google Docs.
The Word file is written by dskripchenko/php-docx, by Denis Skripchenko. Papercut maps its layout onto
Word's paragraphs and tables; php-docx writes the file. Thank you.
Documentation: Word export
Word, LibreOffice and Google Docs lay out the file themselves, so spacing and page breaks can differ slightly from the PDF.
Install
composer require papercut/docx
It needs PHP 8.4 with ext-zip, and papercut/core.
Use
use Papercut\Docx\DocxExporter; $document->export(new DocxExporter())->save('invoice.docx');
With papercut/laravel installed too, Papercut::view('invoice', $data)->docx()->download('invoice.docx'), and
?format=docx on a preview route.
What readers see
Word, LibreOffice and Google Docs lay out the pages themselves, so page breaks can land a line or two away from the PDF's. Columns flow as paragraphs, rows become borderless tables at the widths the PDF uses, and a box with padding, a border or a background becomes a one-cell table.
- Each run of pages with the same size, margins, header, footer and layers becomes a Word section, so pages keep their own setup and headers.
- An image, QR code or SVG in a background (before anything else in it), or alone in an overlay place, becomes a floating picture at the place the PDF draws it, on every page. Word draws it with the header, so an overlay sits behind the body's text.
- Fonts are named, not embedded: the reader's machine supplies them.
- Pictures Word can't take as they are are drawn at the size the PDF gives them: WebP and AVIF images, image
coverand opacity, and plain QR codes needext-gd; styled QR codes needext-imagickandbacon/bacon-qr-code; SVG needs anext-imagickthat reads SVG. Without them, these are left out and reported. - Opacity is drawn by blending each faded colour onto what lies beneath it; text backgrounds keep their exact colour.
- Corner radius on boxes, other content in background and overlay layers, a border or background on a layer picture, PDF page templates and embedded PDF pages are left out and reported (strict mode throws on them).
Approximations and omissions are reported through ExportOptions::onWarning with the node's path, as with HTML
export. How the layout itself is written (rows as tables, boxes as one-cell tables, colours with transparency blended
onto white, fonts by name) applies to every document and isn't reported each time.