Skip to content

Add MarkdownToPDF and CreateInvoiceFromStructuredData samples#7

Open
datalogics-robb wants to merge 3 commits into
datalogics:develop-21from
datalogics-robb:add-markdown-and-invoice-samples
Open

Add MarkdownToPDF and CreateInvoiceFromStructuredData samples#7
datalogics-robb wants to merge 3 commits into
datalogics:develop-21from
datalogics-robb:add-markdown-and-invoice-samples

Conversation

@datalogics-robb

Copy link
Copy Markdown
Contributor

Rewrites the two new DocumentConversion samples from apdfl-csharp-dotnet-samples (PRs datalogics/apdfl-csharp-dotnet-samples#106 and #109, ported to develop-21 in #114) using the Modern C++ interface.

MarkdownToPDF

Converts a practical Markdown subset directly to a newly created, tagged PDF: ATX/setext headings, emphasis with CommonMark-style flanking rules, inline code with backdrop, strikethrough, links (inline/reference/autolink/bare, drawn as working LinkAnnotation + URIAction), ordered/unordered/task lists, fenced code blocks with language title rows and preserved indentation, blockquotes, pipe tables with per-column alignment, horizontal rules, and an HTML-lite subset normalized before parsing. Text is laid out with Font::measure_text_width; CJK wraps per character and CJK/Cyrillic/Greek fall back to installed fonts via Font::is_text_representable. --self-test runs the parser tests without writing a PDF.

CreateInvoiceFromStructuredData

Builds a tagged PDF invoice from JSON metadata, CSV line items, a JSON style sheet, and a local PNG logo (tagged Figure with alt text). The line-item table repeats its header on continuation pages; footers/rules/boxes are emitted as artifacts. When enabled in the metadata, the document is secured with Document::secure (AES-256, owner password) so it can be viewed and printed but not edited. JSON/CSV parsing is a small self-contained parser, keeping APDFL the only dependency.

Notes

  • Both samples build the structure tree with StructTreeRoot / StructElement::add_marked_content_ref — the Modern C++ API assigns MCIDs and maintains the parent tree automatically, so the tagging code is much simpler than the .NET equivalents.
  • Verified on macOS against ModernCppSDK 21.1.0: both samples build clean, self-tests pass, all bundled sample documents convert, the structure trees were validated with the ListStructTree sample, and the rendered pages were visually inspected.
  • Character classification in the Markdown parser is deliberately ASCII-explicit rather than <cctype>: APDFL's Library init changes the process locale, which otherwise misclassifies UTF-8 continuation bytes (this bit during development).
  • Also adds the missing CreateDocFromWebPage entry to the DocumentConversion README and corrects the sample count in CLAUDE.md.
  • Batch directory conversion (--recursive) from the .NET MarkdownToPDF is intentionally not carried over.

🤖 Generated with Claude Code

datalogics-robb and others added 3 commits July 19, 2026 15:43
Rewrite of the .NET MarkdownToPDF sample using the Modern C++ interface:
parses a practical Markdown subset (headings, lists, tables, code blocks,
blockquotes, links, emphasis, HTML-lite), lays text out with
Font::measure_text_width, and builds the logical structure tree with
StructElement::add_marked_content_ref while drawing. Includes parser
self-tests and the sample documents from the .NET repo.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rewrite of the .NET sample using the Modern C++ interface: builds a tagged
PDF invoice from JSON metadata, CSV line items, a JSON style sheet, and a
local PNG logo, then applies an owner-password restriction with
Document::secure (AES-256). JSON and CSV are parsed by a small parser in
the sample so APDFL stays the only dependency. Includes self-tests and the
bundled data files from the .NET repo.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Also adds the missing CreateDocFromWebPage entry and corrects the
DocumentConversion sample count.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants