Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

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
Laravel Cloud

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

Visit Laravel Cloud
Tinkerwell logo

Tinkerwell

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

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

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

PhpStorm
Laravel Cloud logo

Laravel Cloud

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

Laravel Cloud
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
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

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

Shift
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
Lucky Media logo

Lucky Media

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

Lucky Media
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
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Generate, Parse, and Convert Documents in PHP with Paperdoc image

Generate, Parse, and Convert Documents in PHP with Paperdoc

Read article
Spatie Shares Their Coding Guidelines as AI Skills image

Spatie Shares Their Coding Guidelines as AI Skills

Read article
AI Generative Engine Optimization for Laravel image

AI Generative Engine Optimization for Laravel

Read article
Attach PDFs Directly to Mailables in laravel-pdf 2.6.0 image

Attach PDFs Directly to Mailables in laravel-pdf 2.6.0

Read article
Composer 2.9.6 Fixes Two Perforce Command Injection Vulnerabilities image

Composer 2.9.6 Fixes Two Perforce Command Injection Vulnerabilities

Read article
Ship AI with Laravel: Your AI Agent Has Amnesia. Let's Fix It. image

Ship AI with Laravel: Your AI Agent Has Amnesia. Let's Fix It.

Read article