Examples & reference

Printing on the school's letterhead

Every app that prints anything meets the same wall: Arabic shaping, RTL, a font that renders it, margins, and a header the school recognises as its own. Solved separately in each app it is solved differently in each app — a school ends up holding six documents in six layouts, none of them its letterhead, and the one thing it wanted, that these came from its school, is the thing none of them has.

The engine already knows all of it, because the school configured it once in the report builder.

The division of labour

The template is the frame, and the school owns it: logo, header, footer, watermark, margins, paper size, orientation.

The body is yours, and you pass it in. A template carries no content of its own.

How to use it

use App\Services\PartnerApi\Reports\Templates\ListReportTemplates;
use App\Services\PartnerApi\Reports\Templates\RenderReportTemplate;

// 1) Offer the school's letterheads so a person can choose one
$templates = app(ListReportTemplates::class)();

// 2) Print your content on it
$pdf = app(RenderReportTemplate::class)($templates[0]->id, [
    ['type' => 'heading',  'text' => 'كشف الدرجات', 'level' => 'h1'],
    ['type' => 'info-row', 'label' => 'الطالب', 'value' => 'أحمد صالح'],
    ['type' => 'table',
     'headers' => ['المادة', 'الدرجة'],
     'rows'    => [['الرياضيات', '95'], ['العلوم', '88']]],
    ['type' => 'divider'],
]);

// $pdf = ['filename' => …, 'mime' => 'application/pdf', 'bytes' => '%PDF…']

Block types

heading (level: h1/h2/h3, text) · text (html) · info-row (label, value) · table (headers, rows) · divider · spacer · image

An unknown type is refused, not skipped. Silently dropping a block produces a document short by one section that says nothing about it, and a report missing a row is worse than a report that failed to print.

Scope

reports.builder.read — nothing here writes. Printing on somebody's letterhead is a different act from redesigning it, and no app does the second.

Bytes come back, not a URL

A stored file needs a lifetime, a cleanup policy and an access rule, for a document that may carry a named child's marks. Handing back the bytes leaves all three with the app that asked.


View the whole guide on one page · ↧ Raw Markdown