1. Go to this page and download the library: Download popphp/pop-pdf 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/ */
popphp / pop-pdf example snippets
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
$document = new Document();
$document->addFont(Font::ARIAL);
$page = $document->createPage(Page::LETTER);
$page->addText(new Text('Hello World', 12), Font::ARIAL, 50, 742);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
use Pop\Pdf\Document\Page\Image;
$document = new Document();
$document->addFont(Font::ARIAL);
$page = $document->createPage(Page::LETTER);
$page->addText(new Text('Look at this image:', 12), Font::ARIAL, 50, 742);
$page->addImage(Image::createImageFromFile('my-image.jpg'), 50, 380);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
// Pass a valid document object and a path/filename
Pdf::writeToFile($document, 'path/to/my-document.pdf');
use Pop\Pdf\Pdf;
// Pass a valid document object and a path/filename
Pdf::outputToHttp($document, 'my-document.pdf', true);
use Pop\Pdf\Pdf;
$doc = Pdf::importFromFile('path/to/document.pdf');
use Pop\Pdf\Pdf;
// Import pages 2, 4 and 6 from the PDF document
$doc = Pdf::importFromFile('path/to/document.pdf', [2, 4, 6]);
use Pop\Pdf\Pdf;
$doc = Pdf::importRawData($rawData, [2, 4, 6]);
use Pop\Pdf\Pdf;
$doc = Pdf::importFromImages($arrayOfImages);
use Pop\Pdf\Pdf;
$text = Pdf::extractTextFromFile('path/to/document.pdf');
use Pop\Pdf\Pdf;
$text = Pdf::extractTextFromData($pdfStream);
use Pop\Pdf\Document;
$document = new Document();
$document->setCompression(true);
use Pop\Pdf\Document;
$document = new Document();
$document->setOrigin(Document::ORIGIN_TOP_LEFT);
use Pop\Pdf\Document;
use Pop\Pdf\Document\Page;
$pageLetter = new Page(Page::LETTER);
$pageCustom = new Page(500, 1000); // Custom width and height
$document = new Document();
$document->addPages([$pageLetter, $pageCustom]);
use Pop\Pdf\Document;
use Pop\Pdf\Document\Page;
$document = new Document();
$pageLegal = $document->createPage(Page::LEGAL);
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
$document = new Document();
$document->addFont(Font::HELVETICA_BOLD);
$page = $document->createPage(Page::LETTER);
$page->addText(new Text('Hello World', 12), Font::HELVETICA_BOLD, 50, 742);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
$font = new Font('/path/to/some/font.ttf');
$document = new Document();
$document->embedFont($font);
$page = new Page(Page::LETTER);
$page->addText(new Page\Text('Hello World', 36), $font->getName(), 50, 600);
$document->addPage($page);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Document\Page\Text;
$text = new Text('Hello World', 12);
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
$document = new Document();
$document->addFont(Font::ARIAL);
$longString = 'Lorem ipsum [...really long string...] anim id est laborum.';
$text = new Text($longString, 12);
$text->setCharWrap(80, 16); // Set the wrap at 80 characters and a leading of 16
$page = $document->createPage(Page::LETTER);
$page->addText($text, Font::ARIAL, 50, 742);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
$document = new Document();
$document->addFont(Font::ARIAL);
$document->createStyle('normal', Font::ARIAL, 12);
$page = $document->createPage(Page::LETTER);
$page->addText($text, 'normal', 50, 742); // The second parameter can either be a font or a reference to a style
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
$document = new Document();
$document->addFont(Font::ARIAL);
$longString = 'Lorem ipsum [...really long string...] anim id est laborum.';
$text = new Text($longString, 12);
// Create a left-aligned bounding area with the
// X between 50 and 350; leading set 16
$text->setAlignment(Alignment::createLeft(50, 350, 16));
$page = $document->createPage(Page::LETTER);
$page->addText($text, Font::ARIAL, 50, 742);
Pdf::writeToFile($document, 'my-document.pdf');
// Create a right-aligned bounding area with the
// X between 250 and 550; leading set 16
$text->setAlignment(Alignment::createRight(250, 550, 16));
// Create a center-aligned bounding area with the
// X between 50 and 350; leading set 16
$text->setAlignment(Alignment::createCenter(200, 412, 16));
use Pop\Pdf\Document\Font;
$font = new Font(Font::HELVETICA_BOLD);
$width = $font->getStringWidth('Hello World', 12);
var_dump($width);
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Image;
$document = new Document();
$page = $document->createPage(Page::LETTER);
$page->addImage(Image::createImageFromFile('my-image.jpg'), 50, 422);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Image;
$image = Image::createImageFromFile('my-image.jpg');
$image->resizeToWidth(120);
$document = new Document();
$page = $document->createPage(Page::LETTER);
$page->addImage($image, 50, 622);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Path;
use Pop\Color\Color;
$document = new Document();
$path = new Path(Path::FILL_STROKE);
$path->setFillColor(Color::rgb(155, 20, 20))
->setStrokeColor(Color::rgb(81, 125, 153))
->setStroke(5)
->drawRectangle(50, 400, 320, 240);
$page = new Page(Page::LETTER);
$page->addPath($path);
$document->addPage($page);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
use Pop\Pdf\Document\Page\Annotation\Url;
$document = new Document();
$document->addFont(Font::ARIAL);
$page = $document->createPage(Page::LETTER);
$page->addText(new Text('Visit Google', 12), Font::ARIAL, 50, 742);
$page->addUrl(new Url(100, 15, 'https://www.google.com/'), 50, 742);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Document\Page\Text;
use Pop\Pdf\Document\Page\Annotation\Link;
$document = new Document();
$document->addFont(Font::ARIAL);
$page1 = $document->createPage(Page::LETTER);
$page1->addText(new Text('This is an internal link', 12), Font::ARIAL, 50, 742);
$page2 = $document->createPage(Page::LETTER);
$page2->addText(new Text('This is the destination', 12), Font::ARIAL, 50, 742);
// Create a link to page 2 and set the zoom to 110%
$link = new Link(120, 15, 10, 752);
$link->setPageTarget(2)
->setZTarget(110);
$page1->addLink($link, 50, 742);
Pdf::writeToFile($document, 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Build\Html\Parser;
$document = new Document();
$document->addFont(Font::ARIAL);
$page = $document->createPage(Page::LETTER);
$parser = new Parser($document);
$parser->parseHtmlFile('test.html');
$parser->process();
Pdf::writeToFile($parser->document(), 'my-document.pdf');
use Pop\Pdf\Pdf;
use Pop\Pdf\Document;
use Pop\Pdf\Document\Font;
use Pop\Pdf\Document\Page;
use Pop\Pdf\Build\Html\Parser;
$html = <<<HTML
<h1>Hello World!</h1>
HTML;
$css = <<<CSS
h1 {
font-family: sans-serif;
color: #f00;
font-weight: normal;
}
h3 {
font-family: serif;
color: #009dff;
}
.red {
font-weight: bold;
color: #f00;
}
.img-med {
width: 200px;
}
CSS;
$document = new Document();
$document->addFont(Font::ARIAL);
$page = $document->createPage(Page::LETTER);
$parser = new Parser($document);
$parser->parseHtml($html, __DIR__);
$parser->parseCss($css);
$parser->process();
Pdf::writeToFile($parser->document(), 'my-document.pdf');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.