1. Go to this page and download the library: Download paperdoc-dev/paperdoc-lib library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
paperdoc-dev / paperdoc-lib example snippets
use Paperdoc\Support\DocumentManager;
use Paperdoc\Document\Style\TextStyle;
$doc = DocumentManager::create('pdf', 'My Report');
$doc->openSection()
->addParagraph('Hello, Paperdoc!', TextStyle::make()->setBold());
DocumentManager::save($doc, 'output/report.pdf');
use Paperdoc\Document\{Document, Section, Metadata, ListBlock};
use Paperdoc\Document\Style\TextStyle;
$doc = Document::make('md', 'Release notes v0.5.0')
->setProperties(
Metadata::make()
->setAuthor('Alice')
->setKeywords('release, changelog, paperdoc')
->setLanguage('en-US')
);
$section = $doc->openSection();
$section->addElement(\Paperdoc\Document\Heading::make('Getting started', 2, 'intro'));
$section->addBulletList()
->addText('Install the library')
->addText('Run the quick start')
->addText('Read the docs');
$section->addCodeBlock("composer
use Paperdoc\Document\{Image, Section};
use Paperdoc\Document\Style\PageSetup;
use Paperdoc\Enum\PageSize;
$cover = Section::make('cover')->setPageSetup(
PageSetup::fromSize(PageSize::A4)
->setPadding(0) // 1, 2, 3 or 4 values (CSS shorthand)
->setBackgroundImage(Image::make('cover.jpg')) // full-bleed image
);
$body = Section::make('body')->setPageSetup(
PageSetup::fromSize(PageSize::A4, PageSetup::ORIENTATION_LANDSCAPE)
->setPadding(50)
->setBackgroundColor('#F8F5EC') // solid color
);
$square = Section::make('back-cover')->setPageSetup(
PageSetup::custom(500, 500) // any width × height in pt
->setBackgroundImage(Image::make('back.jpg'))
);
use Paperdoc\Document\Style\PageSetup;
$page->setPageSetup(
PageSetup::fromSize(PageSize::A4)
->setBackgroundImage(Image::make('hero.jpg'))
->setBackgroundSize(PageSetup::BG_SIZE_COVER) // default
);
use Paperdoc\Document\TextZone;
use Paperdoc\Document\Style\{ParagraphStyle, TextStyle};
use Paperdoc\Enum\Alignment;
$cover->addTextZone(x: 40, y: 40, width: 515, height: 90)
->setBackgroundColor('#0B1437')
->setBorder('#FFFFFF', 0.8)
->setPadding(16)
->addText(
'Paperdoc — Cover title',
TextStyle::make()->setBold()->setFontSize(20)->setColor('#FFFFFF'),
ParagraphStyle::make()->setAlignment(Alignment::LEFT),
);
// Long lorem with the ellipsis strategy: text is truncated to fit
// exactly the visible height and the last visible line ends with "…".
$cover->addTextZone(x: 40, y: 160, width: 250, height: 260)
->setPadding(12)
->setBackgroundColor('#FFFFFF')
->setBorder('#1F2937', 0.5)
->setOverflow(TextZone::OVERFLOW_ELLIPSIS)
->addText($veryLongText,
TextStyle::make()->setFontSize(10)->setColor('#111827'),
ParagraphStyle::make()->setLineSpacing(1.25),
);
use Paperdoc\Document\Style\{RunningElement, TextStyle};
use Paperdoc\Enum\Alignment;
use Paperdoc\Support\DocumentManager;
$doc = DocumentManager::create('pdf', 'Quarterly report');
$doc->setHeader(
RunningElement::make('{title}')
->setAlignment(Alignment::LEFT)
->setStyle(TextStyle::make()->setFontSize(9)->setItalic()->setColor('#FFFFFF'))
);
$doc->setFooter(
RunningElement::make('Page {page} / {pages} · {date}')
->setAlignment(Alignment::CENTER)
->setStyle(TextStyle::make()->setFontSize(9)->setColor('#FFFFFF'))
);
use Paperdoc\Document\Style\RunningElement;
// Document-level: every page gets this footer by default.
$doc->setFooter(RunningElement::make('Page {page} / {pages}'));
// Cover page: NO footer at all.
$cover = $doc->openSection('cover')->hideFooter();
// Body pages: inherit the document footer.
$body = $doc->openSection('body');
// (nothing to do — automatic fallback)
// Colophon: per-section override.
$colophon = $doc->openSection('colophon')
->setFooter(RunningElement::make('— Fin —'));
use Paperdoc\Document\Style\ParagraphStyle;
$body = ParagraphStyle::make()
->setLineSpacing(1.4)
->setFirstLineIndent(18.0); // ~6mm — classic book body indent
$paragraph->setStyle($body);
use Paperdoc\Document\Style\TextStyle;
$eyebrow = TextStyle::make()
->setFontSize(10)
->setBold()
->setColor('#888')
->setLetterSpacing(2.0); // wide tracking for the eyebrow
$paragraph->addRun(new TextRun('CHAPITRE PREMIER', $eyebrow));
use Paperdoc\Document\HorizontalRule;
use Paperdoc\Enum\Alignment;
// Quick: full-width default-styled rule.
$section->addRule();
// Customised: 50%-width centred grey hairline.
$section->addRule()
->setWidth('50%')
->setThickness(0.75)
->setColor('#aaaaaa')
->setAlignment(Alignment::CENTER)
->setMargins(8.0, 12.0);
// Pure absolute pt width.
$section->addRule()->setWidth(140.0)->setColor('#1F3763');
use Paperdoc\Exceptions\PaperdocException;
try {
$doc = Paperdoc::open('report.docx');
} catch (PaperdocException $e) {
// Any Paperdoc error ends up here.
}
use Paperdoc\Support\DocumentManager;
use Paperdoc\Document\Section;
use Paperdoc\Document\Link\TextLink;
$doc = DocumentManager::create('md', 'Release notes');
$section = Section::make('main');
$section->addText(
'See the full changelog',
null,
TextLink::make('https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CHANGELOG.md', '', 'Changelog')
);
$doc->addSection($section);
echo DocumentManager::renderAs($doc, 'md');
// [See the full changelog](https://github.com/paperdoc-dev/paperdoc-lib/blob/main/CHANGELOG.md "Changelog")
use Paperdoc\Support\DocumentManager;
// <w:hyperlink r:id="…"> elements are parsed and attached to their TextRun
$doc = DocumentManager::open('report.docx');
// Links are rendered as safe [label](url) — labels with ] and URLs with spaces
// or parentheses are escaped/wrapped automatically.
file_put_contents('report.md', DocumentManager::renderAs($doc, 'md'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.