PDF/A
PDF/A (ISO 19005) is the PDF that archives, courts, public bodies and banks ask for: a file that carries everything it needs to look the same decades from now. Lpdf writes PDF/A-2a, PDF/A-2b, PDF/A-2u, PDF/A-3a, PDF/A-3b and PDF/A-3u when the document asks for it in its output, and the render gives the date the file carries.
<lpdf version="1"> <assets> <font name="body" src="fonts/Radley-Regular.ttf"/> </assets> <document font="body"> <meta title="Annual report" author="Finance"/> <output pdfa="2u"/> <section> <layout margin="48pt"> <text font-size="24pt">Annual report</text> <text>Kept as PDF/A: the fonts, the colors and the metadata travel with the file.</text> </layout> </section> </document></lpdf>L.document({ font: 'body', assets: { fonts: [{ name: 'body', src: 'fonts/Radley-Regular.ttf' }] }, meta: { title: 'Annual report', author: 'Finance' }, output: { pdfa: '2u' } }, [ L.section(NoAttr, [ L.layout({ margin: '48pt' }, [ L.text({ fontSize: '24pt' }, ['Annual report']), L.text(NoAttr, ['Kept as PDF/A: the fonts, the colors and the metadata travel with the file.']), ]), ]),])L.document(DocumentAttr(font='body', assets=DocumentAssets(fonts=[FontAttr(name='body', src='fonts/Radley-Regular.ttf')]), meta=DocumentMeta(title='Annual report', author='Finance'), output=DocumentOutput(pdfa='2u')), [ L.section(NoAttr, [ L.layout(LayoutAttr(margin='48pt'), [ L.text(TextAttr(font_size='24pt'), ['Annual report']), L.text(NoAttr, ['Kept as PDF/A: the fonts, the colors and the metadata travel with the file.']) ]) ])])L.document(new DocumentAttr().font("body").assets(new DocumentAssets().fonts(List.of(new FontAttr().name("body").src("fonts/Radley-Regular.ttf")))).meta(new DocumentMeta().title("Annual report").author("Finance")).output(new DocumentOutput().pdfa("2u")), List.of( L.section(NoAttr, List.of( L.layout(new LayoutAttr().margin("48pt"), List.of( L.text(new TextAttr().fontSize("24pt"), List.of("Annual report")), L.text(NoAttr, List.of("Kept as PDF/A: the fonts, the colors and the metadata travel with the file.")) )) ))))L.Document(new() { Font = "body", Assets = new DocumentAssets(Fonts: [new FontAttr { Name = "body", Src = "fonts/Radley-Regular.ttf" }]), Meta = new() { Title = "Annual report", Author = "Finance" }, Output = new() { PdfA = "2u" } }, [ L.Section(NoAttr, [ L.Layout(new() { Margin = "48pt" }, [ L.Text(new() { FontSize = "24pt" }, ["Annual report"]), L.Text(NoAttr, ["Kept as PDF/A: the fonts, the colors and the metadata travel with the file."]), ]), ]),])L::document(new DocumentAttr(font: 'body', assets: new DocumentAssets(fonts: [new FontAttr(name: 'body', src: 'fonts/Radley-Regular.ttf')]), meta: new DocumentMeta(title: 'Annual report', author: 'Finance'), output: new DocumentOutput(pdfa: '2u')), [ L::section(NoAttr, [ L::layout(new LayoutAttr(margin: '48pt'), [ L::text(new TextAttr(fontSize: '24pt'), ['Annual report']), L::text(NoAttr, ['Kept as PDF/A: the fonts, the colors and the metadata travel with the file.']), ]), ]),])The pdfa attribute
Section titled “The pdfa attribute”pdfa is an attribute of output, the element of document that says how the file is written.
| Attribute | Type | Default | Description |
|---|---|---|---|
pdfa |
2a 2b 2u 3a 3b 3u |
— | Writes the PDF as PDF/A-2b, which keeps the look of every page, or PDF/A-2u, which also maps all text to Unicode so it can be searched and copied, or PDF/A-2a, which also tags the file with the structure a screen reader reads, or the same levels of part 3, PDF/A-3b, PDF/A-3u and PDF/A-3a, which also carry attachments of any kind. Without it the PDF is a plain one |
Parts 2 and 3 of the standard allow transparency, so opacity, shadows and gradients are kept. Part 3 is part 2 with files of any kind attached, such as the XML of an e-invoice: a PDF/A-3 file that carries factur-x.xml is a Factur-X e-invoice. A file can be PDF/A and PDF/UA, the tagged PDF a screen reader reads, at once: <output pdfa="2u" pdfua="1"/>, or at level a, <output pdfa="2a" pdfua="1"/>. What combines with what says which other settings go with PDF/A and which are refused, and Standards and print which standard fits which job.
What the file gets
Section titled “What the file gets”- Every font embedded, cut down to the characters the document uses, with a map back to Unicode.
- An XMP packet that names the part and the level, with the title, author, subject, keywords and creator of
meta, the producer and the dates, the same as the document’s information dictionary. - The sRGB output intent: a color profile that gives the RGB colors and images their meaning.
- The date of the render as both its creation and its modification date, and a file ID, the same for the same document.
- Links that print.
- Everything the document has, on screen and in print: print and screen content (
ocg) shows everywhere, so the archive copy holds both. - At level a, the structure of a tagged PDF: see Level a.
Lpdf’s own tests check a document at each of the six levels with veraPDF, the PDF Association’s reference validator, on every change. To check a file of yours, run veraPDF on it: it reads the level the file declares and checks it against that level’s rules.
Level a
Section titled “Level a”Level a, 2a or 3a, is level u with the structure of a tagged PDF: what each text, heading, table, list, link, footnote and image is, in reading order, with headers, footers and borders marked as decoration. Lpdf writes the same structure as for PDF/UA, from the same attributes: role makes a text a heading, alt describes an image or a barcode, and lang on meta gives the language.
Level a asks for the structure and not for what PDF/UA asks of the document. Without pdfua, a level-a document may have no title and no lang, its headings may skip levels, and an img or a barcode without alt is decoration, which a screen reader skips. That file is valid PDF/A-2a, but a screen reader can’t tell what its images show. For a file a screen reader can use, write pdfua="1" beside it: the render then refuses what PDF/UA refuses, and the file is PDF/A and PDF/UA both.
<lpdf version="1"> <assets> <font name="body" src="fonts/Radley-Regular.ttf"/> </assets> <document font="body"> <meta title="Annual report" lang="en"/> <output pdfa="2a" pdfua="1"/> <section> <layout margin="48pt"> <text role="h1" font-size="24pt">Annual report</text> <text>Tagged for screen readers, and kept for the archive.</text> </layout> </section> </document></lpdf>L.document({ font: 'body', assets: { fonts: [{ name: 'body', src: 'fonts/Radley-Regular.ttf' }] }, meta: { title: 'Annual report', lang: 'en' }, output: { pdfa: '2a', pdfua: '1' } }, [ L.section(NoAttr, [ L.layout({ margin: '48pt' }, [ L.text({ role: 'h1', fontSize: '24pt' }, ['Annual report']), L.text(NoAttr, ['Tagged for screen readers, and kept for the archive.']), ]), ]),])L.document(DocumentAttr(font='body', assets=DocumentAssets(fonts=[FontAttr(name='body', src='fonts/Radley-Regular.ttf')]), meta=DocumentMeta(title='Annual report', lang='en'), output=DocumentOutput(pdfa='2a', pdfua='1')), [ L.section(NoAttr, [ L.layout(LayoutAttr(margin='48pt'), [ L.text(TextAttr(role='h1', font_size='24pt'), ['Annual report']), L.text(NoAttr, ['Tagged for screen readers, and kept for the archive.']) ]) ])])L.document(new DocumentAttr().font("body").assets(new DocumentAssets().fonts(List.of(new FontAttr().name("body").src("fonts/Radley-Regular.ttf")))).meta(new DocumentMeta().title("Annual report").lang("en")).output(new DocumentOutput().pdfa("2a").pdfua("1")), List.of( L.section(NoAttr, List.of( L.layout(new LayoutAttr().margin("48pt"), List.of( L.text(new TextAttr().role("h1").fontSize("24pt"), List.of("Annual report")), L.text(NoAttr, List.of("Tagged for screen readers, and kept for the archive.")) )) ))))L.Document(new() { Font = "body", Assets = new DocumentAssets(Fonts: [new FontAttr { Name = "body", Src = "fonts/Radley-Regular.ttf" }]), Meta = new() { Title = "Annual report", Lang = "en" }, Output = new() { PdfA = "2a", PdfUa = "1" } }, [ L.Section(NoAttr, [ L.Layout(new() { Margin = "48pt" }, [ L.Text(new() { Role = "h1", FontSize = "24pt" }, ["Annual report"]), L.Text(NoAttr, ["Tagged for screen readers, and kept for the archive."]), ]), ]),])L::document(new DocumentAttr(font: 'body', assets: new DocumentAssets(fonts: [new FontAttr(name: 'body', src: 'fonts/Radley-Regular.ttf')]), meta: new DocumentMeta(title: 'Annual report', lang: 'en'), output: new DocumentOutput(pdfa: '2a', pdfua: '1')), [ L::section(NoAttr, [ L::layout(new LayoutAttr(margin: '48pt'), [ L::text(new TextAttr(role: 'h1', fontSize: '24pt'), ['Annual report']), L::text(NoAttr, ['Tagged for screen readers, and kept for the archive.']), ]), ]),])Level a gives every character of Unicode’s private use area, U+E000 to U+F8FF and planes 15 and 16, words of its own, since it means only what its font draws, as an icon font’s symbols do. Lpdf doesn’t write those words, so such a character is an error at level a: write the character it stands for if Unicode has one, show the symbol as an img with alt, or use level u. The same text renders at levels b and u, and with pdfua alone.
The date
Section titled “The date”A PDF/A file carries the date it was made, and the engine has no clock, so the render gives it as createdOn: an ISO 8601 date, or date and time, such as 2026-10-31 or 2026-10-31T09:30:00+01:00. A fraction of a second is dropped.
import { L } from '@lpdfio/lpdf'import { writeFileSync } from 'node:fs'
L.engine() .render(xml, { createdOn: new Date().toISOString() }) .then((pdf) => writeFileSync('report.pdf', pdf))from datetime import datetime, timezonefrom pathlib import Pathfrom lpdf import L, RenderOptions
pdf = L.engine().render(xml, RenderOptions(created_on=datetime.now(timezone.utc).isoformat()))
Path('report.pdf').write_bytes(pdf)import io.lpdf.EngineOptions;import io.lpdf.L;import io.lpdf.RenderOptions;import java.nio.file.Files;import java.nio.file.Path;import java.time.Instant;
byte[] pdf = L.engine(new EngineOptions().srcFallback(src -> Files.readAllBytes(Path.of(src)))) .render(xml, new RenderOptions().createdOn(Instant.now().toString()));
Files.write(Path.of("report.pdf"), pdf);Java reads the font’s src only through the engine’s srcFallback: without it the font isn’t embedded, which PDF/A refuses.
using Lpdf;using Lpdf.Engine;
var pdf = L.Engine(new EngineOptions { SrcFallback = File.ReadAllBytes }) .Render(xml, new RenderOptions { CreatedOn = DateTimeOffset.Now.ToString("o") });
await File.WriteAllBytesAsync("report.pdf", pdf);C# reads the font’s src only through the engine’s SrcFallback: without it the font isn’t embedded, which PDF/A refuses.
<?phprequire_once 'vendor/autoload.php';
use Lpdf\Engine\RenderOptions;use Lpdf\L;
$pdf = L::engine()->render($xml, new RenderOptions(createdOn: date('c')));
file_put_contents('report.pdf', $pdf);A document built in code asks for PDF/A in its output too: output: { pdfa: '2u' } in JavaScript, DocumentOutput in the other SDKs, where C# names it PdfA.
Errors
Section titled “Errors”Lpdf writes what PDF/A needs and repairs nothing of the document’s own. Each of these stops the render with an error that says what to change:
- text in a built-in font, such as the default Helvetica, which is not embedded: declare a font in
assetsand set it withfonton the document or the text. The error names the text - a font declared in
assetswhose file was not loaded - a font whose license forbids embedding it
- a character the font has no glyph for, which a reader would draw as an empty box
- a CMYK color or gradient, or a spot color whose
valueiscmyk(): the sRGB output intent covers RGB colors only - a form field, whose text is drawn in Helvetica
- the digits of a barcode, drawn in Helvetica: set
hrt="false"and write the digits as text if they are needed encrypton the sameoutput: PDF/A forbids encryption, so that an archive can always open the filepdfxon the sameoutput: a PDF/A file keeps to the sRGB profile, and a PDF/X file to the press profileattachmentswith2a,2bor2u: a PDF/A-2 file can carry only files that are PDF/A themselves, which the engine can’t check. Write3a,3bor3uto carry files- an attachment named
factur-x.xmlorxrechnung.xmlwith2a,2bor2u: it makes the file a Factur-X invoice, which is PDF/A-3 - at level a, a
langonmetathat is not a language tag: give one such asen,en-USorde-CH - at level a, a character of Unicode’s private use area, such as an icon font’s symbol: see Level a
- a render without
createdOn, or with one that is not a date