Two Laravel devs that won't disappear on you. Finally! Hire Joel and Aaron from No Compromises.

Generate, Parse, and Convert Documents in PHP with Paperdoc

Last updated on by

Generate, Parse, and Convert Documents in PHP with Paperdoc image

Paperdoc is a PHP library by Zerarka Mohamed Ali Akram for generating, parsing, and converting documents across multiple file formats through a single unified API. Rather than juggling several format-specific packages, Paperdoc gives you one consistent interface for everything from PDFs to spreadsheets. It handles both modern formats (PDF, DOCX, XLSX, PPTX, HTML, CSV, Markdown) and legacy formats (DOC, XLS, PPT), and all of them work bidirectionally — you can both parse existing files and generate new ones in any of them.

Main Features

Document Generation — Create new documents from scratch in any supported format. You work with a structured document model (sections, paragraphs, tables, etc.) that maps cleanly to whichever output format you choose:

use Paperdoc\Support\DocumentManager;
use Paperdoc\Document\Style\TextStyle;
 
$doc = DocumentManager::create('pdf', 'My PaperDoc Demo Document');
 
$boldStyle = TextStyle::make()
->setBold()
->setColor('#f9332b')
->setFontSize(14);
 
$section = $doc->openSection();
$section->addHeading('Generate, Parse, and Convert Documents in PHP with Paperdoc');
$section->addParagraph('Paperdoc is a PHP library by Zerarka Mohamed Ali Akram for generating, parsing, and converting documents across multiple file formats through a single unified API.');
$section->addParagraph(
'Convert PDF, HTML, CSV, DOCX, XLSX, PPTX, Markdown and more.',
$boldStyle
);
 
DocumentManager::save($doc, 'output/paperdoc.pdf');

Parsing — Load existing files into a normalized in-memory model. This gives you a consistent data structure to work with regardless of the source format:

$doc = DocumentManager::open('paperdoc.pdf');
 
foreach ($doc->getSections() as $section) {
foreach ($section->getParagraphs() as $paragraph) {
echo $paragraph->getText();
}
}

Format Conversion — Transform documents between any two supported formats in a single call:

DocumentManager::convert('paperdoc.pdf', 'paperdoc.docx', 'docx');

Rendering to string — Rather than writing to disk, you can render a document directly to a string, which is useful for returning responses or piping output:

$html = DocumentManager::renderAs($doc, 'html');

OCR Processing — Extract text from scanned documents using Tesseract, making it possible to work with image-based or non-machine-readable PDFs. You'll need the Tesseract binary installed on your system and the path configured in config/paperdoc.php.

AI Augmentation — An optional Neuron AI integration adds LLM-powered capabilities such as document summarization, translation, and structured data extraction.

Thumbnails — Generate preview images of any document via thumbnail() or thumbnailDataUri() for inline use. Note that high-quality rendering requires third-party binaries depending on the format — LibreOffice for Office files, and Imagick or Ghostscript for PDFs.

Batch Processing — Open and process multiple documents in a single call:

$docs = DocumentManager::openBatch([
'file1.pdf',
'file2.docx',
'file3.xlsx',
]);

Laravel Integration

Paperdoc ships with first-party Laravel support including a ServiceProvider, Facade, and Artisan commands, targeting Laravel 11+. The Facade is registered automatically via package auto-discovery, giving you a clean Paperdoc interface:

use Paperdoc\Facades\Paperdoc;
 
$doc = Paperdoc::create('md', 'Paperdoc + Laravel');
$doc->openSection()
->addParagraph('Paperdoc also works great with Laravel!');
 
Paperdoc::save($doc, storage_path('app/private/articles/paperdoc-and-laravel.pdf'));
 
Paperdoc::convert('articles/paperdoc-and-laravel.md', 'articles/paperdoc-laravel.pdf', 'pdf');
 
$html = Paperdoc::renderAs($doc, 'html');
 
$docs = Paperdoc::openBatch([
'file1.pdf',
'file2.docx',
'file3.xlsx',
]);

You can find the source code on GitHub and learn more on the official Paperdoc website.

Yannick Lyn Fatt photo

Staff Writer at Laravel News and Full stack web developer.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media

The latest

View all →
Typed Objects for Eloquent with Expressive image

Typed Objects for Eloquent with Expressive

Read article
Malware Blocking and Dependency Policies in Composer 2.10 image

Malware Blocking and Dependency Policies in Composer 2.10

Read article
Aegis for Laravel: Scaffolding and Validation Helpers for Value Objects image

Aegis for Laravel: Scaffolding and Validation Helpers for Value Objects

Read article
Playa: Cookie-Based Temporary Players for Laravel image

Playa: Cookie-Based Temporary Players for Laravel

Read article
Scheduler Attributes and Listener Discovery Control in Laravel 13.12.0 image

Scheduler Attributes and Listener Discovery Control in Laravel 13.12.0

Read article
The PHP Foundation Launches an Ecosystem Security Team image

The PHP Foundation Launches an Ecosystem Security Team

Read article