Novis\Pdf\Document::withStandard
$document->withStandard(Standard $standard): Document$document->withStandard( Standard $standard, ): Document
Sets the PDF standard that the file follows: PdfA2b, PdfA3b or PdfUa1.
Every PDF file that render makes has tags. Tags tell a screen reader which parts of a page are headings, tables or images. A standard adds strict checks to the file.
Document::Standard::PdfA2bandPdfA3bare PDF/A, for files kept in an archive for many years. A PDF/A file needs a creation time, which you set withwithCreationTime. It cannot have a password.Document::Standard::PdfA3bis also the standard for an electronic invoice, withwithInvoiceXml.Document::Standard::PdfUa1is PDF/UA, for accessible files. It needs a<title>, and every image needsalttext.
A document that breaks its standard makes render throw a LogicError that says what is wrong. A document has one standard at most.
withStandard returns a new Document and does not change the one you called it on.
The examples below make a certificate for an archive, make an accessible report, and show the errors for a document that breaks its standard.
Parameters
$standardStandard
Return value
Returns Document.
Changelog
| Version | Change |
|---|---|
0.0.6 | Each Novis\Pdf\Document method that returns a new document now starts with with, for example withHeader() and withPassword(). created() is now withCreationTime(). |
Examples
A certificate to archive
<?nvs// Shows a certificate in landscape, made as a PDF/A file for a long-term archive.use Novis\Pdf\Document;use Novis\Pdf\Reader;
string $html = "<html lang=\"en\"><head><title>Certificate</title>" . '<style>@page { size: A4 landscape } body { text-align: center }</style></head>' . '<body><h1>Certificate</h1><p>Ada Lovelace finished the course Bookkeeping for Shops.</p></body></html>';
// PDF/A needs a creation time, so the program sets one with `withCreationTime`.var $rendered = Document::fromHtml($html) ->withStandard(Document::Standard::PdfA2b) ->withCreationTime(Core\Time\Instant::fromIso('2026-03-01T09:00:00Z')) ->render();
// This prints the page count and the title in the file.var $reader = Reader::open($rendered->bytes);echo $reader->pageCount, " page\n";echo $reader->metadata->title ?? 'no title', "\n";1 pageCertificateAn accessible report
<?nvs// Shows a report made as a PDF/UA file, which a screen reader can read aloud.use Novis\Pdf\Document;
// PDF/UA needs a `<title>`, and each image needs `alt` text.string $chart = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"200\" height=\"80\">" . "<rect width=\"60\" height=\"80\" fill=\"#888\"/><rect x=\"80\" width=\"60\" height=\"50\" fill=\"#888\"/></svg>";string $html = "<html lang=\"en\"><head><title>Sales report</title></head><body>" . "<h1>Sales report</h1><img src=\"chart.svg\" alt=\"Sales fell from 80 to 50 orders.\">" . '<table><tr><th>Month</th><th>Orders</th></tr><tr><td>May</td><td>80</td></tr>' . '<tr><td>June</td><td>50</td></tr></table></body></html>';
var $rendered = Document::fromHtml($html) ->withAsset('chart.svg', $chart as bytes) ->withStandard(Document::Standard::PdfUa1) ->render();
// This prints the page count of the finished file.echo $rendered->pageCount, " page\n";1 pageA document that breaks the standard
<?nvs// Shows the error a render throws when the document does not meet its standard.use Novis\Pdf\Document;
string $html = "<html lang=\"en\"><head><title>Price list</title></head>" . "<body><img src=\"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'/>\">" . '<p>Tea 2.50 EUR</p></body></html>';
// The image has no `alt` text, so the file is not PDF/UA.// `render` throws a `LogicError` that says what is wrong.try { Document::fromHtml($html)->withStandard(Document::Standard::PdfUa1)->render();} catch (LogicError $e) { echo $e->message, "\n";}
// PDF/A needs a creation time. This document has none, so `render` throws.try { Document::fromHtml('<p>Tea 2.50 EUR</p>')->withStandard(Document::Standard::PdfA3b)->render();} catch (LogicError $e) { echo $e->message, "\n";}the document does not meet PDF/UA-1: an image has no `alt` textthe document does not meet PDF/A-3b: the document has no creation time. Set it with `withCreationTime()`