Haru (PDF)¶
Haru is a PECL extension that wraps libharu, a free, cross-platform C library for generating PDF documents from scratch. It exposes classes such as HaruDoc and HaruPage that build a document page by page: adding text with a chosen font and size, drawing lines and shapes, embedding images, and setting document metadata.
Unlike libraries that convert HTML or templates into PDF, Haru works at a lower level, closer to the PDF drawing model itself, giving precise control over layout and placement at the cost of more verbose code. It has no dependency on an external binary or headless browser, which makes it lightweight to deploy.
Haru is less commonly used today than pure-PHP, Composer-installable alternatives such as dompdf, mPDF, or the FPDF family, which most projects prefer for ease of installation and HTML-based templating.
<?php
$pdf = new HaruDoc();
$pdf->addPage();
$page = $pdf->getCurrentPage();
$page->setSize(HaruPage::SIZE_A4, HaruPage::PORTRAIT);
$font = $pdf->getFont('Helvetica');
$page->setFontAndSize($font, 24);
$page->beginText();
$page->textOut(50, 750, 'Hello, PDF!');
$page->endText();
$pdf->save('/tmp/hello.pdf');
?>
See also libharu.
Related : Graphic Draw (GD), imagick
Related packages : dompdf/dompdf, mpdf/mpdf