PHP code example of arabel / pdf

1. Go to this page and download the library: Download arabel/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/ */

    

arabel / pdf example snippets


use Arabel\Pdf\Document;
use Arabel\Pdf\DocumentStyle;

$style = new DocumentStyle();
$style->h1(22, [15, 55, 120], 'B', 12)
      ->h2(12, [15, 55, 120], 'B', 8)
      ->p(9,  [60, 60, 60],   '',  5.5);

$doc = new Document('Helvetica', $style);

$doc->addPage()
    ->h1('Monthly Report')
    ->h2('Sales — April 2026')
    ->hr()
    ->spacer()
    ->p('Summary of current month sales compared to the previous period.')
    ->output('report.pdf', 'F');

// Default header — applied to every addPage()
$doc->setHeader()
    ->bg([15, 55, 120])
    ->fg([255, 255, 255])
    ->left('ARABEL SRL', 'Software & Digital Products')
    ->right('FATTURA', '# INV-2026-0042')
    ->height(22);

// Named header — applied explicitly
$doc->setHeader('allegato')
    ->bg([15, 55, 120])
    ->fg([255, 255, 255])
    ->left('ALLEGATO A — Dettaglio attività', 'Fattura INV-2026-0042');

// Footer with page number
$doc->setFooter()
    ->left('Arabel Srl — P.IVA IT09876543210')
    ->right('Pagina {page}');

$doc->addPage();                // → 'default' header + footer
$doc->addPage('P', 'allegato'); // → 'allegato' header + footer
$doc->addPage('P', false);      // → no header, footer only

$doc->addPage()
    ->h1('Dashboard')
    ->spacer()

    ->row()
        ->col(8)->p('Left side — takes 8 of 12 columns.')
        ->col(4)->h2('€ 24,500')
    ->endRow()

    ->row()
        ->col(4)->h2('142 PDFs')
        ->col(4)->h2('38 upgrades')
        ->col(4)->h2('94% satisfaction')
    ->endRow()
    ->row()
        ->col(4)->p('generated this month')
        ->col(4)->p('Free → Pro conversions')
        ->col(4)->p('satisfaction index')
    ->endRow()

    ->output('dashboard.pdf', 'F');

$doc->row()
    ->col(3)->image('logo.png')        // auto height from aspect ratio
    ->col(3)->image('badge.png', 20)   // forced 20 mm height
    ->col(6)->h1('Company Name')
->endRow();

$doc->addPage()
    ->h1('Product List')
    ->spacer()

    ->table(['Product', 'Category', 'Qty', 'Revenue'])
        ->widths([3, 2, 1, 1])
        ->align(['L', 'L', 'C', 'R'])
        ->tr(['Arabel PDF',     'Library', '142', '€ 0'])
        ->tr(['Arabel Builder', 'Tool',      '38', '€ 1,862'])
        ->tr(['Arabel Suite',   'Bundle',    '12', '€ 2,388'])
    ->endTable()

    ->output('products.pdf', 'F');

->table(['Descrizione', 'Qty', 'Prezzo', 'IVA', 'Totale'])
    ->tr(['Arabel PDF', '1', '€ 49,00', '22%', '€ 59,78'])
    ->tr([
        ['text' => 'Subtotale:', 'colspan' => 4, 'align' => 'R'],
        ['text' => '€ 59,78',                    'align' => 'R'],
    ])
->endTable()

$doc->panel()
        ->bg([15, 55, 120])
        ->fg([255, 255, 255])
        ->padding(5)
        ->h2('TOTALE FATTURA:')
        ->b('€ 13.344,36')
    ->endPanel();

$style = new DocumentStyle();

// Fluent configurators (recommended)
$style->h1(22, [15, 55, 120], 'B', 12)
      ->h2(12, [15, 55, 120], 'B', 8)
      ->p(9,  [60, 60, 60],   '',  5.5);

// Table style
$style->tableHeadBg = [15, 55, 120];
$style->tableHeadFg = [255, 255, 255];
$style->tableAltBg  = [235, 241, 255];
$style->tableRowH   = 7.0;
$style->tableLineH  = 5.0;

use Arabel\Pdf\Pdf;

$pdf = new Pdf();

$pdf->addPage()
    ->setFont('Helvetica', 14)
    ->setTextColor(41, 98, 255)
    ->text(20, 30, 'Hello from Pdf')
    ->setFillColor(240, 240, 240)
    ->cell(100, 10, 'Cell with border', 1, 1, 'C')
    ->setDrawColor(180, 0, 0)
    ->line(10, 60, 200, 60)
    ->image('logo.png', 10, 70, 40)
    ->output('output.pdf', 'F');

$doc = new Document();

$doc->addPage()
    ->h1('Invoice #1042');

// Drop to Pdf for a precise watermark
$doc->raw()
    ->setFont('Helvetica', 60)
    ->setTextColor(230, 230, 230)
    ->text(25, 120, 'DRAFT');

// Back to Document
$doc->spacer()
    ->table(['Description', 'Amount'])
        ->tr(['Consulting', '€ 800'])
    ->endTable()
    ->output('invoice.pdf', 'F');