In one of our WPF ClickOnce projects we need to be able to generate a PDF report from an existing template (which is itself a PDF). The requirements are not complex:
- C# (.Net framework 4.8)
- Open an existing PDF document that contains fields and use it as a template (each field has a name, and during the pdf file generation the fields should be replaced with formatted text)
- Add basic formatted text (bold/italic etc)
- "Flow" text between areas
- Possibility to digitally sign the document
Not very fancy requirements but a good opportunity to compare available libraries that may be up to the task.
We initially chose ABCpdf because it has good documentation and seemed affordable. Unfortunately only after developing the feature did we realise that their license is per computer, not per software project. Our app is a WPF app deployed via ClickOnce, which can be run on any client machine. Everything worked fine on our dev box until we wanted to deploy it. Then we realized that the "SuperGoo" company expects you to install ABCPdf on each computer that will generate pdf-s. We got around this by including the necessary DLL-s in our app only to then find out that we should buy $4,000+ of licenses to purchase an enterprise license to run it on a few computers. Well, I guess they don't want to bother with "small" clients/projects like us! A shame, because we would have had no problem shelling out $400 but 4K no way.
We then looked into Aspose.PDF. This looked like a good solution but costs $1k. They have live chat and they offered to give a discount if we write a blog post about their product - we may consider doing this at some point in time. We played around with their product. They seem to have rolled two PDF libraries into one, and because of this certain things should be done with one API while others should be done with another API, and this makes things somewhat complicated. But overall it seems like a pretty good library and we were going to use it until we realized that Syncfusion's "Essential PDF" solution is available for free for small companies. So this is what we went with.
Unfortunately, it seems that Syncfusion's "Essential PDF" is a repackaged version of "Spire PDF". Perhaps they bought the rights, I don't know. In any case it turned out that their PDF library is usable but very, very poorly designed. Things are much more difficult to implement than with ABCpdf or Aspose.PDF. For example, flowing plain text from one area to another is not well documented and somewhat difficult to implement with plain text, and pretty much impossible to do with the PdfHTMLTextElement (which can draw rich "HTML-styled" text). Speaking of the PdfHTMLTextElement, if you get stuck trying to break your text into separate lines, you have to type "<br/>" exactly, "<br>" throws an error while other variations like "<br />" or "<br></br>" simply don't work (and the only place where you can find this out is in a thread on their support forum). Occasionally a call would simply hang forever (for example if pagination was set to on with a rich html text field, calling the .Draw() method would just hang forever).
Another problem we ran into was editing an existing PDF. This really isn't possible with Syncfusion - you can't just edit a text element for example. And if you want to add a new text element to a page you have to use a separate method when working with a PDF that was opened (graphics.DrawString) as opposed to a PDF you create in code (PdfTextElement.Draw). The two methods are quite similar but the first is lacking in several respects, for example you can't draw text into a predefined "box". So then you try to import pages from an existing document onto a newly created document, but that doesn't work well, forms are messed up and other issues arise.
The documentation is also quite raw and lacking in many places. It has some example code but the result (what it actually looks like in a generated pdf) is never included, so you're left wondering what certain functions actually do. Many methods/functions/parameters have no documentation at all. For example, what do the "PdfLayoutType" options "OnePage" and "Paginate" actually do? The documentation offers a one-sentence explanation. Or how do these options interact with PdfLayoutBreakType, which has options "FitColumnsToPage" / "FitElement" / "FitPage"? We couldn't figure it out.
Still, the documentation is better than what is available for PdfSharp. But PdfSharp is free while Syncfusion's product starts at around a grand.
And iText7? Well, they don't even make their pricing public, and you know that if you need to get a custom quote for a product then it ain't gonna be cheap!
Disclaimer: this is our company blog mostly for our own benefit and we make no money off of it, and you won't find any affiliate links here.
A good starting point: https://www.reddit.com/r/dotnet/comments/8a83jh/what_is_the_current_best_way_of_creating_pdf/
So that's our story so far. Here's a list of PDF libraries we found and our impressions:
Listed in order of popularity (avg daily downloads on Nuget)...\
dl/d = avg-downloads-per-dayccccccjgkgdtenrvfrdjjtlftijnknbuukjkcckulngg
PdfSharp ◆ 1,524 dl/d ◆ 👎
By far the most popular package in large part probably because it's open-source and free.
However, there doesn't seem to be any straightforward support for signing pdf documents, and the existing documentation is a little convoluted and lacking.
iText7 ◆ 778 dl/d ◆ $? ◆ 👎
Originally started as "iTextSharp", an open-source and free port of a java library for editing pdf-s, it was rebranded "iText" and rewritten and fully commercialized. The original iTextSharp lib has been deprecated.
Currently there is an "open-source" version licensed under AGPL - but that means your own app has to be open-source to use it. No published pricing available for the commercial edition, you have to fill in a contact for to get a quote and give a valid phone number. Not a fan of that, so as awesome as it might be, we're skipping it for now. Also way too much legal banter on the website and the documentation is difficult to navigate.
→ API docs
Aspose.PDF for .NET ◆ 654 dl/d ◆ $999+
$999 per project which is out of our budget range although you can get a bit of a discount if you write a blog entry or are willing to publicize their product in some other way. Documentation seems solid and it has a lot of features.
Syncfusion Essential PDF ◆ 538 dl/d ◆ $995+
Again, $995 per project is just too expensive for our needs, however small companies can get a license for free so this is what we're using at the moment.
Also, lots of reports of large memory usage and crashes...
IronPDF ◆ 303 dl/d ◆ $399+ ◆ 👎
$399/project which is acceptable pricing for us. Lots of great examples and the documentation is easy to navigate. Easy to sign pdf-s as well. Unfortunately, it's a more limited library than the previous ones because it uses an embedded Chromium web browser to render PDF from html. Their own FAQ explains this well:
When using iTextSharp PDF library, each piece of pdf text, graphic, table or line is “plotted” or drawn onto a PDF. This model allows precision but many developers complain that it is time consuming to generate PDFs - and that it is very time hard to closely match existing design styles or web assets.
The iTextSharp DLL has advanced PDF manipulation APIs that are powerful, and follow the PDF standard closely.
When viewing iTextSharp documentation, we see is a port of a Java Library called "iText". In keeping, the methodology and programatic interface has a distinct Java flavor.
In contrast, Iron PDF uses an embedded, full Chromium based web browser renderer to convert html to pdf (including C# code examples) allowing developers to generate PDFs from HTML, images and CSS.
From: "Is IronPDF an iTextSharp Alternative?"
ABCpdf ◆ 256 dl/d ◆ $329 - $5,000+ ◆ 👍
ABCpdf gets up close and personal! Because it doesn’t use any print drivers and goes Direct to PDF™ it’s incredibly fast. ABCpdf incorporates virtually every feature you're ever likely to need in a PDF library.
They have a great page explaining digital signatures. The library also seems to have a lot of features. Their documentation is also very easy to understand and navigate. Their licensing sucks though and is not at all appropriate for ClickOnce apps (they want you to buy a license for each client computer that might use it).
GemBox.Document for .NET ◆ 210 dl/d ◆ $240+ ◆ 👎
This seems to be a more limited library for now. For example, "GemBox.Pdf supports filling in a PDF interactive form. Currently, only filling in of toggle button fields (PdfCheckBoxField and PdfRadioButtonField) is supported."
Spire.PDF ◆ 166 dl/d ◆ $599+
Seems a bit expensive, so that's as far as we got. Also, it seems like their product is the same under the hood as what Syncfusion gives away for free for small companies. The documentation is the same word-for-word as the Syncfusion documentation...we suspect Syncfusion bought Spire.PDF or at least resale rights to it?
Please read the intro for an overview of our experiences with the Syncfusion product.
Apitron.PDF.Kit ◆ 78 dl/d ◆ $1,300+
Apitron PDF Kit is a .NET component that allows you to do whatever you want with PDF files. Add text, images, drawings, sign documents and much more.
You can also edit existing content using its friendly and easy to use API. It’s 100% managed code and doesn't require special manipulations to run with any .NET framework version starting from 2.0..
Sounds good but way too expensive!
Some others we didn't spend so much time with...
Essential Objects EO.Pdf ◆ 162 dl/d ◆ $799+
Select.Pdf ◆ 126 dl/d ◆ $499+
DynamicPDF ◆ 61 dl/d ◆ $899+
ComponentPro PDF Document ◆ 7 dl/d ◆ $599
(couldn't find a nuget package)
Adobe® PDF Library™ SDK by Datalogics
There are also a lot of html-to-pdf-converter libs, such as:
EvoPDF ◆ 200 dl/d ◆ $450+
EVO HTML to PDF Converter is a .NET library that can be easily integrated in any type of .NET application to convert web pages, HTML strings and streams to PDF or to image.