Skip to content

Immagini

Incorpora JPEG, PNG e GIF nei tuoi documenti PDF.

Immagine Base

php
$pdf = Document::create()->addPage();

$pdf->image(
    file: '/path/to/logo.png',
    x: 10,
    y: 10,
    width: 50,
    height: 20
);

Parametri Posizione

php
// Posizione specifica
$pdf->image('/path/to/chart.png', x: 20, y: 50, width: 100, height: 80);

// Larghezza auto (mantiene aspect ratio)
$pdf->image('/path/to/photo.jpg', x: 10, y: 10, width: 80);

// Ridimensiona per adattare
$pdf->image('/path/to/banner.png', x: 0, y: 0, width: 210); // Larghezza A4

Formati Supportati

  • JPEG — Photo, immagini complesse
  • PNG — Trasparenza, loghi
  • GIF — Animazioni (frame singolo)
  • WebP — Formato moderno

Testo Alternativo (PDF/UA)

php
$pdf->image(
    file: '/path/to/chart.png',
    x: 10,
    y: 10,
    width: 100,
    height: 80,
    alt: 'Grafico vendite Q1 2026'
);

Esempio Completo

php
$pdf = Document::create()
    ->setTitle('Rapporto con Immagini')
    ->addPage();

// Logo header
$pdf->image('/assets/logo.png', x: 10, y: 10, width: 40, height: 15);

// Contenuto
$pdf->setY(30)
    ->setFont('Helvetica', 'B', 16)
    ->cell(0, 10, 'Rapporto Vendite 2026', newLine: true)
    ->ln(5);

// Grafico
$pdf->image('/charts/sales.png', x: 20, y: 50, width: 170, height: 100);

$pdf->save('report-with-images.pdf');

Rilasciato sotto licenza LGPL-3.0-or-later.