MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

SimplePdf

MMO\pdf · 1 symbole · générée le 27 Oct 2026

class

SimplePdf

SimplePdf.php:24

A new PDF written from code -- an invoice, a receipt, a report: headings, text, labelled fields, a table whose columns fit their content, totals. Built on the bundled FPDF (src/vendor/fpdf) and its core fonts; texts are UTF-8, written in the fonts' own encoding (cp1252: accents, €, œ; a character outside it prints as ?).

class MMO\pdf\SimplePdf
Espace de noms
MMO\pdf
Every method returns the document, to chain them; `fpdf()` gives FPDF itself for anything else (an image, a line, another font), at the current position.
$pdf = (new SimplePdf('Invoice 2026-0042')) ->heading('Invoice 2026-0042') ->fields(['Customer' => 'Acme', 'Date' => '26/10/2026']) ->table(['Item', 'Qty', 'Unit price', 'Total'], [['Design', '2', '450,00 €', '900,00 €']], ['L', 'R', 'R', 'R']) ->totals(['Total' => '900,00 €']); return $pdf->response('invoice-2026-0042.pdf'); // from a route or a page: shown in the browser $bytes = $pdf->output(); // or the bytes: they start with `%PDF`

Index

fontthe font of every text: Helvetica, Times or Courier
lineHeightthe height of a line, in mm
pdf
sizethe size of body text, in points
encode($text) static$text in the core fonts' encoding (cp1252)
fields($fields)Labelled values, one per line: the labels bold, in a column as wide as the longest
fit($text, $width)$text cut to fit $width mm, with ...
fpdf()FPDF itself, for what this class does not do (http://www.fpdf.org) -- its texts are cp1252: encode
heading($text, $size)A title, bold, $size points
measure($titles, $rows)Each column's width: what its widest text needs, scaled to fill the page
output()The PDF's bytes
response($filename, $inline)The PDF as the answer to a request -- what a route or a page returns
save($filename)Writes the PDF to $filename
space($height)An empty space, $height mm high
table($headers, $rows, $align, $widths)A table: a shaded header row, then a row per item.
text($text, $style, $align)A paragraph, wrapped to the page's width; $style B, I, BI or ``
totals($totals)Totals under a table, aligned on the right: the label, then its value, the last line bold
__construct($title, $orientation, $format)

Propriétés4

font

the font of every text: Helvetica, Times or Courier

string $font = 'Helvetica'
Type
string

lineHeight

the height of a line, in mm

float $lineHeight = 6.0
Type
float

pdf

protected FPDF $pdf
Type
FPDF

size

the size of body text, in points

float $size = 10.0
Type
float

Méthodes14

encode($text)

staticSimplePdf.php:53

$text in the core fonts' encoding (cp1252)

static function encode(string $text): string
$textstring
retournestring

fields($fields)

SimplePdf.php:84

Labelled values, one per line: the labels bold, in a column as wide as the longest

function fields(array $fields): static
$fieldsarray
retournestatic

measure($titles, $rows)

SimplePdf.php:183

Each column's width: what its widest text needs, scaled to fill the page

protected function measure(array $titles, array $rows): array
$titlesarray
$rowsarray
retournearrayfloat>

response($filename, $inline)

SimplePdf.php:166

The PDF as the answer to a request -- what a route or a page returns

function response(string $filename = 'document.pdf', bool $inline = true): MMO\core\server\StreamResponse
$filename = 'document.pdf'stringthe name the browser gives the file
$inline = truebooltrue: the browser shows it; false: it saves it
retourneStreamResponse

space($height)

SimplePdf.php:75

An empty space, $height mm high

function space(float $height = 4.0): static
$height = 4.0float
retournestatic

table($headers, $rows, $align, $widths)

SimplePdf.php:108

A table: a shaded header row, then a row per item. Each column is as wide as its content needs, the widths scaled to fill the page; a text too long for its column is cut with .... The header row is repeated on every new page.

function table(array $headers, iterable $rows, array $align = [], array $widths = []): static
$headersarraythe columns' titles
$rowsiterableeach row's values, in the columns' order
$align = []arrayeach column's alignment: L, C or R (a number: R) -- L by default
$widths = []arrayeach column's width in mm, rather than measured
retournestatic

text($text, $style, $align)

SimplePdf.php:67

A paragraph, wrapped to the page's width; $style B, I, BI or ``

function text(string $text, string $style = '', string $align = 'L'): static
$textstring
$style = ''string
$align = 'L'string
retournestatic

totals($totals)

SimplePdf.php:140

Totals under a table, aligned on the right: the label, then its value, the last line bold

function totals(array $totals): static
$totalsarray
retournestatic

__construct($title, $orientation, $format)

SimplePdf.php:38
function __construct(string $title = '', string $orientation = 'P', string $format = 'A4')
$title = ''stringthe document's title, in its properties (not printed: heading)
$orientation = 'P'stringP portrait or L landscape
$format = 'A4'stringA4, A5, Letter...