Skip to content

feat!: render on Linux — remove the GDI+ dependency - #18

Merged
poxet merged 9 commits into
masterfrom
fix/linux-gdi-plus
Sep 4, 2026
Merged

poxet merged 9 commits into
masterfrom
fix/linux-gdi-plus

Conversation

@poxet

@poxet poxet commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #17.

Rendering a template containing a BarCode threw DllNotFoundException at GdiplusStartup on Linux, breaking member-card printing for a consumer that had moved to a Linux App Service. There was no configuration-level workaround.

The report understated the problem

BarCode.Render did use System.Drawing — but so did Image.cs, and, decisively, PdfSharp 1.51's own XImage.FromStream and XFont font resolution. Removing GDI+ from the element code alone would have produced a clean-looking fix that still crashed on Linux, one stack frame deeper.

So this replaces the rendering stack rather than patching the elements.

What changed

2.4 3.0
PDF engine PdfSharp 1.51 + MigraDoc PDFsharp 6.2.4 (MIT)
Imaging System.Drawing.Common none
Barcodes Aspose.BarCode (commercial, unlicensed) ZXing.Net 0.16.11 (Apache-2.0)
Runs on Windows only Windows, Linux, macOS
  • MigraDoc removed entirely. GetDocument built an empty Document whose only job was counting pages; it is now a GetPageCount one-liner.
  • Barcodes are drawn as PDF vector rectangles instead of an embedded raster, so the image path is never touched and bars stay sharp at any print size.
  • ReporterFontResolver resolves registered fonts, then host-installed fonts, then an embedded fallback (from PdfSharp.WPFonts, already in the MIT package). PDFsharp 6 Core resolves nothing on its own — not even on Windows — so this is required, and it is installed automatically.
  • Image.cs rebuilt on XImage, which also fixes the Image element on Linux.
  • Deprecated XUnit implicit conversions replaced with explicit .Point / XUnit.FromPoint.

Verification

69 tests, 0 failures, identical on Windows and on Linux (WSL Ubuntu, .NET 10.0.11) — up from 50 tests with 6 running.

  • New rendering tests cover bar count against the Code 39 symbology, ordering, bounds, and a decode round-trip that reads the drawn bars back with an independent reader.
  • Render_never_touches_the_image_path asserts DrawImage is never called — the regression guard for the Linux fix.
  • A PDF generated on Linux was verified as %PDF-1.7, 3 pages, embedded font subset, zero image XObjects.
  • The packed nuspec declares only PDFsharp and ZXing.Net.
  • Barcodes confirmed to scan on a physical reader.

The 4 tests skipped as "Can't gain access to internal stuff" were stale: InternalsVisibleTo("Tharga.Reporter.Tests") was already present, and the real blocker was Moq's proxy generator, fixed here with InternalsVisibleTo("DynamicProxyGenAssembly2").

Breaking changes — 3.0

  1. PdfSharp type identities changed for anyone referencing PageFormat, RenderData or DebugData. Consumers move to PDFsharp 6.2.4 and rename XFontStyle to XFontStyleEx. Code that only builds templates and calls GetPdfBinary is unaffected.
  2. Font metrics differ on a host lacking the named family. Text still renders via the fallback, but glyph widths change, so line breaks can shift. Install the font or use ReporterFontResolver.Register.
  3. Code 39 now upper-cases instead of discarding. This is a bug fix: 2.x silently dropped characters it could not encode, so abc123 produced a barcode that scanned as 123 and a-b.c scanned as -., with no error. Anything genuinely unencodable now throws. If any codes contain lower-case letters, the barcode they produce changes — worth checking against cards already in circulation.

docs/articles/upgrading-to-3.md covers all three, and docs/articles/fonts.md documents font resolution.

https://claude.ai/code/session_016X21mvHXXY3DxS87J4Eh9V

@poxet
poxet merged commit 3fc9655 into master Sep 4, 2026
6 of 7 checks passed
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Released as v3.0.0 — https://github.com/Tharga/Reporter/releases/tag/3.0.0

@poxet
poxet deleted the fix/linux-gdi-plus branch September 4, 2026 12:38

This branch had an error being deployed

1 failed deployment
prerelease — 0d79c39f Deployed Sep 4, 2026 by poxet via prerelease #33
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.

BarCode rendering fails on Linux: System.Drawing/GDI+ is Windows-only on .NET 8+

1 participant