I create PDF files from C# using LaTeX as an intermediate format. This works very reliable but sometimes takes a bit of tinkering until everything fits.
People here on HN recently recommended Typst as a replacement for LaTeX, but I haven't tried it myself yet.
The wider .NET ecosystem is lacking when trying to step out the mainline. I don't bother hunting for unused, partially implemented .NET libraries anymore and just call out to a process or API call when needing to get something done.
It's not ideal, but when there isn't a good option isn't available in .NET it's usually available in Python/npm. Typically I'll use background jobs when calling out of process for added resiliency/replayability and observability.
I needed this post a year ago when I was looking for this exact thing. I did end up going with Puppeteer because I needed it for something else that I couldn't avoid. I use a large list of flags with it to launch the most minimal version of headless Chrome that I can.
I am going to look into switching to MigraDoc and see if i can drop puppeteer
Oh yeah, PDF. In a past project I created a monster solution:
* Scriban to fill in templates (LaTeX)
* Custom Angular SSR to reuse frontend components (charts etc)
* Playwright to convert SSR output to PDF
* LuaLaTeX to convert LaTeX document + stuff to PDF
Super slow, but very high quality results. Do not try this at home!
>Naturally, I first started looking for permissively licensed libraries, which could be used free of charge and without additional license requirements.
There is a lot of work in a good PDF library, expecting to get it for free feels unreasonable to me.
I've been making my reports in self-contained HTML files[0] and it works out so much better than PDF. It is not constrained by paper sizes, and it lets me add some nifty features. For example, I recently added support for hiding columns in a table using exclusively CSS. The only downside is browsers can render things slightly differently, but for my use cases I don't need pixel-perfect identical rendering.
[0] Images are inlined base64-encoded, CSS/JS embedded with style and script tags. No external assets / no http requests.
At work we were using I think it was GDPicture? Which is now called Nutrient. They started out with a flat fee, royalty free, then their pricing scheme became more hostile over time (per developer, per application licensing, and I don't recall if they wanted to know how many users - which is crazy unless it's a SaaS). I have friends (former coworkers) and family who ask me for advice on software libraries to use for what, since they know I'm a hyper nerd for that sort of thing, last time a former coworker asked what PDF library to use I told them to avoid Nutrient like the plague. There's wanting to be sustainable and then there's greed.
So yeah I too was looking for permissive licensing. The worst part is now its drastically harder for me to suggest any paid alternatives because we don't know that the alternative wont hike up prices on us. It's a really awful spot to be in.
When I used PdfSharp about 9 years ago, it wasn't really designed to import arbitrary PDFs; it crashed or hung on many less common constructs or invalid PDF files. It was really only designed to either create PDFs or edit PDFs created by itself (or MigraDoc, which used it); that it could also import some other PDFs was considered a bonus by its maintainers. I submitted some patches back then to fix the most egregious problems. Hopefully it has improved.
We needed a library to read arbitrary PDF files (although I forgot what exactly we needed to read from them; it wasn't for full rendering) and ended up using PdfSharp, because iText did not respond to our pricing request.
My favorite approach for PDF rasterization was to interop with a simple, custom Java console application that leveraged Apache PdfBox.
This lasted until the log4j exploit, at which point we had to abandon it altogether due to our customers (banks) having a complete meltdown over it at the time.
It's probably still a really good option. I would definitely go back to it in a different context.
We've been using Aspose.PDF for the last 10 years or so in our C# platform, and paying for the license. It's expensive and buggy and has shite support, so a year or so back I decided to see if there was some other library or combination of libraries that could meet our needs. Basically, we needed:
* HTML to PDF
* Compress PDF
* Manual PDF generation
* Text extraction
* No browser engine or other weird dependencies
I researched every library I could find, and downloaded, integrated and tested anything that looked remotely promising.
At the end of all that, I reluctantly handed my company credit card back to Aspose. There simply wasn't any open-source or even just cheaper PDF library that I could actually make work, and all the other paid ones that did work were even more expensive.
If you ever revisit alternatives, you might want to try YakPDF
It gives you:
- HTML → PDF without any browser engine
- PDF compression & optimization
- Simple API for manual PDF generation
- Text extraction
- No native dependencies and cheaper than Aspose
It’s not a full drop-in replacement for every Aspose feature, but it covers the core workflow you mentioned and is much lighter to integrate.
I've been looking for a while for a C++ library that can recognize and extract data tables reliably from PDF documents. Open source or commercial. Anyone know of one?
Can anyone recommend a "print PDF to Laserprinter" library?
I have been looking for a library for C# for some time now that would allow me to print PDF files on a laser printer programmatically. However, I cannot find one. Until now, I have been using Foxit Reader, which I call up via the command line. But this is not ideal for various reasons.
I went through a similar quest recently and I was a bit disappointed there isn't an easy way to convert markdown to pdf (without going through html and puppeteer). It sounds easy, right? I still get flashbacks of having to write a program on paper that outputs justified text, so I won't even attempt it...
> Naturally, I first started looking for permissively licensed libraries, which could be used free of charge and without additional license requirements.
You can skip low-level PDF libs entirely and just generate the PDF from an HTML/CSS template (or plain HTML or URLS). With PDFBolt you design the layout once in HTML/CSS + Handlebars, then your C# code sends JSON and gets a PDF back from the API. That avoids the whole DOM/layout/rendering headache and you don’t have to ship a browser engine yourself.
It’s not a replacement for permissively licensed libraries when you need everything local, but for reports/invoices/etc. it can save a lot of time.
20 comments
[ 5.0 ms ] story [ 98.1 ms ] threadIMHO the list is incomplete without it.
1: https://github.com/ststeiger/PdfSharpCore
People here on HN recently recommended Typst as a replacement for LaTeX, but I haven't tried it myself yet.
It's not ideal, but when there isn't a good option isn't available in .NET it's usually available in Python/npm. Typically I'll use background jobs when calling out of process for added resiliency/replayability and observability.
Which use-cases needing Qt WebKit is an issue?
I am going to look into switching to MigraDoc and see if i can drop puppeteer
Thanks for this great research!
Scriban is totally awesome though.
There is a lot of work in a good PDF library, expecting to get it for free feels unreasonable to me.
I've been making my reports in self-contained HTML files[0] and it works out so much better than PDF. It is not constrained by paper sizes, and it lets me add some nifty features. For example, I recently added support for hiding columns in a table using exclusively CSS. The only downside is browsers can render things slightly differently, but for my use cases I don't need pixel-perfect identical rendering.
[0] Images are inlined base64-encoded, CSS/JS embedded with style and script tags. No external assets / no http requests.
So yeah I too was looking for permissive licensing. The worst part is now its drastically harder for me to suggest any paid alternatives because we don't know that the alternative wont hike up prices on us. It's a really awful spot to be in.
We needed a library to read arbitrary PDF files (although I forgot what exactly we needed to read from them; it wasn't for full rendering) and ended up using PdfSharp, because iText did not respond to our pricing request.
This lasted until the log4j exploit, at which point we had to abandon it altogether due to our customers (banks) having a complete meltdown over it at the time.
It's probably still a really good option. I would definitely go back to it in a different context.
* HTML to PDF
* Compress PDF
* Manual PDF generation
* Text extraction
* No browser engine or other weird dependencies
I researched every library I could find, and downloaded, integrated and tested anything that looked remotely promising.
At the end of all that, I reluctantly handed my company credit card back to Aspose. There simply wasn't any open-source or even just cheaper PDF library that I could actually make work, and all the other paid ones that did work were even more expensive.
- HTML → PDF without any browser engine - PDF compression & optimization - Simple API for manual PDF generation - Text extraction - No native dependencies and cheaper than Aspose
It’s not a full drop-in replacement for every Aspose feature, but it covers the core workflow you mentioned and is much lighter to integrate.
https://rapidapi.com/yakpdf-yakpdf/api/yakpdf (open via firefox)
Partially OT:
Can anyone recommend a "print PDF to Laserprinter" library?
I have been looking for a library for C# for some time now that would allow me to print PDF files on a laser printer programmatically. However, I cannot find one. Until now, I have been using Foxit Reader, which I call up via the command line. But this is not ideal for various reasons.
Tick looking for the host.
It’s not a replacement for permissively licensed libraries when you need everything local, but for reports/invoices/etc. it can save a lot of time.