Repository navigation
print: a built-in <qrcode> element renders a QR code from a line-preserving payload (#8608) - #8611
Merged
Merged
Conversation
…erving payload (#8608) A .print template could not print a QR code - the payment code (EPC069-12, "SEPA credit transfer") mainstream invoicing tools put on an invoice. <qrcode> is now a built-in tag. Its payload is the element's bound text with the line breaks kept (per-line trim of the template's indentation, the blank first/last formatting line dropped, interior empty lines kept), or the single-line value="..." attribute; size (points, default 90), align and level (L/M/Q/H, default M). A blank payload, or one too long for a QR code, renders nothing - like an unreadable <image>. The parser library stays dependency-free: it models the node (QrCodeNode, TagRegistry.registerLinePreserving) and hands the payload to a QrCodeEncoder; engine-document's PrintQrCodeEncoder encodes it with ZXing as UTF-8 bytes, so Cyrillic names scan back. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause
A
.printtemplate could not print a QR code.sdk.utils.QrCode/QRCodeFacadegenerate an image andTagRegistrydocumentedregistry.register("qrcode")as its extension example, but nothing connected them:<qrcode>in a shipped template wasUnknown tag <qrcode>, and the parser collapses every element's text to one line, so a line-oriented payload (the EPC069-12 "SEPA credit transfer" payment code) could not even be written.Change
<qrcode>is a built-in tag:<text>) with its line breaks kept, or the single-linevalue="..."attribute (wins when not blank).\n; every line is trimmed of leading/trailing spaces and tabs (the template's indentation); the first line is dropped when blank and so is the last (exactly one each - the formatting around the content); every other line stays, empty ones included. A line holding only a placeholder stays a line whatever it resolves to.size- side of the printed square in points, quiet zone included (default 90);level-L/M/Q/H, defaultM;align. A wrongsize/levelis a layout error at the attribute.<image>: a payload blank after binding, or too long for a QR code at the level, renders nothing. Works in the flow,row,stack,header/footer, and under<if>.Where the code lives:
modules/parsers/documentstays dependency-free:QrCodeNode,TagRegistry.registerLinePreserving/preservesLines(the parser keeps lines for such tags),renderer.QrCodeEncoder+QrCodeLevel, andXslFoRenderer(imageResolver, qrCodeEncoder)emitting anfo:external-graphicofsizexsize. Default encoderNONErenders no QR code.components/engine/engine-document:PrintQrCodeEncoder(ZXingcore3.5.4, the versionapi-utilsalready ships) draws a 1-bit PNG - 8 px per module plus the 4-module quiet zone - inlined as adata:URI, wired inPrintRenderer, so the Print button,attach: printandfunction: Snapshotall get it. The payload is written as UTF-8 bytes without an ECI header.QRCodeFacadeis not reused: it encodes ISO-8859-1 (a Cyrillic name becomes?) and takes no level.stamp),engine-document/CLAUDE.md,.claude/docs/document-templates.md.There is no HTML preview of a
.printin the platform (the Settings preview renders the PDF), so the PDF renderer is the only one touched. No generator or template changed, so nosample-intent-*fixture is affected.Verification
Run locally in a worktree:
mvn test -pl modules/parsers/document,components/engine/engine-document- parsers-document 169 tests, engine-document 94 tests, 0 failures.QrCodeTest(20): parse (lines kept, indentation trimmed, CRLF/CR, only one formatting line dropped at each end, entities), bind (11-line EPC payload exact, interior empty lines kept, empty placeholder line stays,valueshort form), render (payload + level reach the encoder, defaults, blank/declined payload renders nothing, row/stack/footer/<if>, invalidlevel/size).PrintQrCodeEncoderTest(9): the PNG is scanned back with ZXing to the exact 12-line Cyrillic payload at every level; trailing empty line kept; geometry; an oversized payload is declined softly.PrintRendererTest.aPaymentQrCodeScansBackFromTheRenderedPdf: a real PDF throughPrintRenderer.renderPdf(parse, bind, XSL-FO, FOP), page rasterized at 200 DPI with PDFBox (new test-scope dependency, 3.0.3 - the FOP line's fontbox version) and the code scanned off the page: the exact 12-line EPC payload, Cyrillic beneficiary and empty lines included.mvn -T 1C formatter:validatewith the formatter cache wiped - green.mvn -P release ... install -pl modules/parsers/document,components/engine/engine-document(javadoc) - green.Not verified: no scan with a real banking app (the decoder in the tests is ZXing, without a character-set hint);
PrintRenderITwas not run locally.Fixes #8608
🤖 Generated with Claude Code