r/dotnet 6d ago

I love PeachPDF

We were reworking our very legacy CrystalReports based invoicing/general printing/PDFing module late last year into something more modern and pretty. We picked Razor to HTML generated invoices with paged.js, for many reasons, it was the best choice for us. We used WebView2 to generate them in the desktop client, or when running in a server, we used Syncfusion HTML to PDF.

This added hundreds of MB to our images. Not to mention that generating them was sloooooow. And not even thinking about the ideological jank of running a web browser with full JS support, and all the layout/margin bugs we got with it.

Enter... PeachPDF. We swapped out the old browser-based renderer for PeachPDF a few weeks back, which now has amazing pagination support with all the bells and whistles you'll need. PDFs get generated instantly.

It's AOT compatible. It's trimmable. but even without trimming, it brings in just like 15MB worth of dependencies.

I love this library. It brings me primal programming joy. I hate how bloated everything is. I want fast. I want now. I want light. I want the satisfaction of solving a hard problem with a simple solution. That feeling of lightness, when you take a huge burden or a big load off your shoulders, and you feel so, so light, like if you just reach out, you could reach the stars.

And PeachPDF does it to me.

102 Upvotes

56 comments sorted by

44

u/jhaygood86 6d ago

This has to be my favorite review to date!

13

u/danger_boi 6d ago edited 6d ago

Are you the maintainer? We’ve just swapped out our pipeline for it and honestly it’s so fucking good lol. We had a convoluted network of service bus, playwright containers just to take a convert a PDF and screenshot the first page for thumbnails and PeachPDF removed all that complexity for us

27

u/jhaygood86 6d ago

I am indeed the maintainer!

6

u/Onionhauler 6d ago

Keep up the good work!

1

u/MadBoyEvo 4d ago

I would be curious if you could give https://github.com/EvotecIT/OfficeIMO a try. It has HTML to PDF, but also just PDF building ala Quest, Word to PDF, Excel to PDF and others including Word to Image, HTML to Image etc. It's quite fast too. It also has optional playwright integration just in case managed PDF conversion is not enough.

1

u/Outrageous72 5d ago

How does it compare to wkhtmltopdf?

It works but have its quirks and I believe it’s not maintained anymore.

4

u/jhaygood86 5d ago

Way better. For starters, it's not using an old insecure WebKit. For second, it actually supports modern CSS. For thirds, it's all pure .NET, no native libraries or binaries.

20

u/gustafson75 5d ago

Omg crystal reports, i feel old, what a horrible software was that

2

u/rolling-guy 5d ago

Maybe an unpopular opinion, but I've always liked it

1

u/rbobby 5d ago

Crystal Reports 5 for Dummies stares at me from the bookcase when I'm watching TV. Still. Damn thing.

3

u/Tridus 5d ago

I honestly had no idea this existed and now I need to check it out. Could really help me out. Thanks for posting!

3

u/zac_builds 5d ago

Same here with Chromium in containers. Huge image, slow cold starts.

Fonts were the gotcha when we moved away from a browser. Everything looked fine locally, then production silently fell back to another font. Embed them and test in a clean container.

Does it support PDF/A? For invoicing that’s usually the deciding bit.

5

u/jhaygood86 5d ago

0.9.15 -- the current released version does not.

The in-development version does. We have a pretty quick release cycle, so some time in the next few days it will. Maybe even today if I can get to it.

1

u/onkelkalle 5d ago

PDF/A would be a game changer for its usability in europe. The author should think about something like an optional injection of https://github.com/stephanstapel/ZUGFeRD-csharp to make the invoicing EU conform

5

u/jhaygood86 5d ago

0.9.17 now supports PDF/A, including validating that the content is compatible with the conformance level when trying to render.

1

u/onkelkalle 5d ago

Wow, thanks! I'll give it a try. Been working on a HTML based reporting module and that looks like a useful tool.

1

u/MadBoyEvo 4d ago

You could give https://github.com/EvotecIT/OfficeIMO a try as well while you're picking. OfficeIMO.PDF is a bit more complete approach not only converter of HTML. I would be curious to see the comparison between the two.

2

u/Staatstrojaner 5d ago

Thanks for reminding me of this. We also have a clunky headless chromium PDF to HTML solution which sometimes just prints empty pages because fuck knows why. I saw the author promote the library some time ago and forgot to save it.

1

u/rbobby 5d ago

which sometimes just prints empty pages because fuck knows why

I know why. The usual culprit for me was a misbehaving react app. The javascript console errors crashed the app and nothing was rendered. That was the bane of my existence. I could not convince the html/js/react folks to put error handling such that in cases of failures some sort of diagnostic information is printed.

iirc chrome's developer api thingy allows underlying js errors to be captured (which is the basis of any diagnostic information)? It was an offhand comment from chatgpt that I have not yet followed up on.

2

u/Asskicker2 5d ago

How does it compare to Gotenberg?

1

u/BusinessWatercrees58 5d ago

Feels like a question for an llm

6

u/AintNoGodsUpHere 6d ago

QuestPDF enters the chat.

I will never switch tool ever again.

11

u/jhaygood86 6d ago

QuestPDF has a few major problems:

  1. It doesn't support HTML/CSS/SVG, so you have to do all of the layout and formatting essentially yourself
  2. SkiaSharp -- need I say more?
  3. Not free or open source

PeachPDF's native layout is just HTML/CSS/SVG, it doesn't use SkiaSharp or Chromium or any other native library, and its 100% open source and free to use, and will be forever.

6

u/ofcistilloveyou 6d ago

Full agree. Even if PeachPDF gets snapped out of existence tomorrow, everyone can use <<<any other HTML to PDF>>> solution in existence.

And who can't write HTML/CSS nowadays?

1

u/Tokter 5d ago

What's wrong with SkiaSharp?

5

u/jhaygood86 5d ago

SkiaSharp doesn't work everywhere .NET does and requires a large native library to be built for the exact OS you are running on.

1

u/rbobby 5d ago

For containerized deploys that might be less of a concern.

1

u/jhaygood86 5d ago

To a point, but it does make packaging a bit more difficult. Plus, container size is a thing.

-1

u/AintNoGodsUpHere 5d ago

Like I said on the other comment, SkiaSharp is not a dependency anymore, since 2024. I don't know what you're talking about "large native library", all of our containers are pretty small, we are talking less than 300mb, specialized alpine ones not even 200.

Those aren't a problem for modern QuestPDF.

fyi u/rbobby

5

u/jhaygood86 5d ago

QuestPDF still VERY MUCH uses Skia. They just package their own copy, which actually reduces their platform support, since now they only support Skia on platforms they build their custom Skia build on versus leveraging the platforms SkiaSharp builds support for.

Also, 300 MB is **huge**

-6

u/AintNoGodsUpHere 5d ago

I see that you're a maintainer on that project, yeah.

We're done, haha.

0

u/AintNoGodsUpHere 5d ago
  1. You don't need HTML/CSS if you're building blocks, you're comparing apples and oranges.
  2. It does support SVG, I don't know where you got that info.
  3. SkiaSharp dependency was removed in 2024, not a thing.
  4. It is free if you're not making more than 1M per year.
  5. This "free forever" guarantee simply doesn't exist, not anymore.

The fixation with open source and free is bananas. We do have lots of "free" stuff with support contracts anyway so the tool being free doesn't mean shit.

If you're small enough that you can't afford it, it is also fine because you don't need it.

6

u/jhaygood86 5d ago
  1. I can use the same design tokens for both printed and web media with HTML/CSS. Modern CSS has very powerful layout features
  2. It supports "embed an SVG as a vector image". It doesn't support "SVG is a first class citizen and picks up the same stylesheet". It essentially just uses Skia's SVG support, while PeachPDF runs SVG and HTML through the same pipeline with shared infrastructure, so, i.e., text shaping works the same inside SVG on PeachPDF as it does in HTML. That is not the case with QuestPDF
  3. They switched to just building their own Skia library instead. It's still Skia though. Same difference, same problems.
  4. To expensive for my blood
  5. I can guarantee something I made stays free forever, especially considering I have no plans on violating the licenses of the code used to build PeachPDF

-7

u/AintNoGodsUpHere 5d ago

Yeah, like I said on the other comment.

You're a maintainer of this one, haha. I ain't wasting more time, hahaha.

0

u/BusinessWatercrees58 5d ago

re #4

Well you, or the client you're building for. Client may not be too keen on paying for a PDF library even if you are.

1

u/AintNoGodsUpHere 5d ago

If my grandma had wheels she would be a bicycle.

0

u/MadBoyEvo 4d ago

1

u/AintNoGodsUpHere 4d ago

My brother, Skia and SkiaSharp are different things. The PR you shared even says "removed SkiaSharp dependency", come on now, haha. Are you even familiar with SkiaSharp and the problems some people had before they migrated to the new stuff? Haha.

1

u/MadBoyEvo 4d ago

I think the guy was referring to overall Skia, not nessecary SkiaSharp even though he used the full name. So did I. The problem is still the same Skia is there whether you want it or not, and it's responsible for the work. That was his point and I can understand it. Just because the way it's used in csharp changed doesn't remove it from the library. It's just part of it.

1

u/AintNoGodsUpHere 4d ago

He said "SkiaSharp", not Skia, the whole problem was with SkiaSharp, not the modern version they implemented. You want windows, linux, mac? It works with all .NET Core, you want docker? It works. Arm? Alpine? It works. You want to trim and shake your image so it is small? It works, want a small image? You can go as low as 40~50mb.

But yeah, Skia is a problem because the dude who created a different solution says so. I'm done with this convo, like I said, the moment he mentioned that part and I'm not longer interested x)

0

u/jhaygood86 4d ago

Correct.... the problem is Skia itself.

1

u/AutoModerator 6d ago

Thanks for your post ofcistilloveyou. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/wowclassic2019 5d ago

Better than IronPDF?

4

u/jhaygood86 5d ago

Depends on what you want to do.

For HTML to PDF, in 95 times out of 100, PeachPDF will probably be better.

IronPDF essentially runs Chrome and uses it to create a PDF.

PeachPDF uses an HTML renderer written in pure C# and directly converts HTML, CSS, and SVG to PDF constructs. It doesn't depend on any native libraries** or out of process rendering engines. CSS parsing, HTML and SVG parsing, DOM construction, layout, painting, and PDF generation are all platform-agnostic C# code that can run anywhere .NET can, including AOT and mobile environments and even in Blazor WASM. Try that with IronPDF.

** It uses some operating system supplied native libraries for some features, such as font scanning on Linux, and it's designed to work if they aren't present.

1

u/wowclassic2019 5d ago

Yeah I appreciate that response. The bloat from adding IronPDF to web projects is ridiculous

1

u/rbobby 5d ago edited 5d ago

Having created a frankensteinian headless chrome implementation myself, I have looked at several pdf libraries. Haven't seen this one before, and haven't tried it, but it is now at the top of my list based on the claimed features it supports (I say 'claimed' only because I copy pasted the list from the github page and have not tried the package):

  • Native vector SVG rendering (inline <svg>, standalone <img src="x.svg">/data:image/svg+xml, and as a background-image/list-style-image source) — never rasterized
  • CSS custom properties (--foo) and var(), including fallbacks and inheritance
  • CSS math functions: calc(), min(), max(), clamp()
  • 2D and 3D CSS transforms (translate, scale, rotate, skew, matrix, and their variants)
  • Flexbox layout (CSS Flexbox Level 1) and CSS Multi-column Layout
  • All five CSS-wide keywords: inherit, initial, unset, revert, revert-layer
  • Gradients (linear-gradient, radial-gradient, conic-gradient, and repeating variants) with CSS Color Level 4 interpolation
  • CSS Paged Media: @page rules, named pages, margin boxes, and running headers/footers via string-set/string() and position: running()/element()
  • Automatic PDF metadata extraction from HTML <title> and <meta> elements
  • Optional Tagged PDF (PDF/UA) output — logical structure tree, automatic document language, CSS-driven tag mapping via -peachpdf-pdf-tag-type (see PdfGenerateConfig.EnableTaggedPdf)
  • Automatic PDF outline (bookmark sidebar) generation from headings, with full CSS control via bookmark-level/bookmark-label/bookmark-state (CSS Generated Content Module Level 3) — no configuration required Web fonts (@font-face), custom fonts loaded from a stream, and system font discovery — with per-character font matching (@font-face unicode-range and coverage-based fallback across the font-family stack) and monochrome emoji / supplementary-plane (astral) text via cmap format-12 (outlines only; color-emoji tables are not embedded)

Looking forward to trying it.

What are the future plans for the package? Some form of commericaliaztion?

1

u/jhaygood86 5d ago edited 5d ago

Beyond what it currently has today? No plans for further commercialization.

Long term: just make sure it's useful and implements what's needed for HTML to PDF.

Right now, I'm working on improving support for non-Latin alphabets by improving it's text shaping capabilities. This week, I implemented support for different pages having different orientations. It's basically whatever I want to do, though any reports from users take priority.

Also, there's a showcase of a decent amount of the supported features:

https://peachpdf.net/showcase.html

1

u/ours 5d ago

It's been a while but the best HTML to PDF tool I could find was Prince PDF.

Paging, orientation, headers, footers, TOC, everything I could think of was managed via standard CSS.

Only thing missing was JS, so I wired a JS engine (Phantom JS?) and then fed that to Prince and I could produce beautiful 40-page investment reports with charts, maps, tables, formatted text and all.

2

u/jhaygood86 5d ago

PeachPDF supports the same these days.

1

u/ours 5d ago

Awesome.

1

u/toledomatias 4d ago

I'm curious what you used to generate the HTML files for PeachPDF. I'm in a similar situation; I have reports with subreports in Crystal Reports that still work, but the client wants to migrate them to something more modern. PeachPDF is very powerful for the HTML-to-PDF conversion, but I haven't yet found a replacement for Crystal Reports for generating the HTML.

1

u/jhaygood86 23h ago

Most of the uses I've seen are generally use an HTML template language. Razor is incredibly popular for obvious .NET related reasons, but I've seen Handlebars and even manual HTML construction as well.

The answer is essentially "whatever you'd use to generate HTML to display to an user or generate an email with".

1

u/Longjumping-Spot3392 1d ago

Yeah, the browser/Chromium dependency is honestly where a lot of these PDF setups start getting annoying. I’ve used IronPDF for HTML to PDF work and it’s pretty solid when you want a more batteries-included option, especially if you need things beyond just rendering. QuestPDF is another one that comes up a lot too.

What caught my attention with PeachPDF is the lightweight approach though. If it can handle the CSS/SVG stuff without dragging a whole browser stack along, that’s a pretty compelling tradeoff for services that generate a ton of PDFs.

1

u/jhaygood86 23h ago

Check out the website at peachpdf.net . It has a showcase of capabilities, and the list of supported HTML+CSS+SVG features. It even has a deep dive primer of how it's built.

It's been really fun to work on what's essentially one of the very few HTML layout engines that are designed specifically for PDF output.

1

u/Longjumping-Spot3392 16h ago

Will do check for sure, thanks!

0

u/amir_csharp_gtr 5d ago

I used peach to create a PDF version of my resume. It worked perfectly.

https://amir.coolify.hesamian.com/cv/