.NET server based PDF generation
Asked Answered
F

13

11

I'd like to dynamically generate content and then render to a PDF file. This processing would take place on a remote hosting server so using virtual printers etc is out. Does any have a recommendation for a .NET library (pref C#) that would work?

I know that I could generate a bunch of PS code and package it myself but I'd prefer something a little less tricksy at this stage.

Thanks!

Frannie answered 16/1, 2009 at 15:48 Comment(0)
E
6

I have had good success using SharpPDF.

Exordium answered 16/1, 2009 at 15:51 Comment(1)
Right - this looks simple enough to use right away. Does tables and images which is great. Thank you OrbMan.Frannie
P
8

Have a look at http://itextsharp.sourceforge.net/. Its open source.
Tutorial: http://itextdocs.lowagie.com/tutorial/

Planoconcave answered 16/1, 2009 at 15:51 Comment(7)
I use this one myself and it is great. The nice thing is that it also allows you to add passwords to existing PDF files, which was something I couldn't find with some of the other libraries out there.Blythebm
I too have used itextsharp in the past. It's excellent from what I can remember. I believe I also tried the .NET version of PDFlib - apparently I wasn't as impressed, since I ended up doing the project with itextsharp.Hollow
Looks like the last version is from 2005, and built for .NET 1.1. Anything newer out there?Coachandfour
@ Turbulent Intellect: Last Update: May 25 2008 (from: sourceforge.net/projects/itextsharp)Planoconcave
I've used it in the past and liked it. The API is a mess though, so expect a learning curve beyond your usual .NET API.Bereave
Thanks. Cannot tell immediately but this looks like a Java component?Frannie
@ G Forty - Its ported to .Net from a similar Java component. That's why most of tutorials are in Java as well. But they are not too hard to follow.Planoconcave
E
6

I have had good success using SharpPDF.

Exordium answered 16/1, 2009 at 15:51 Comment(1)
Right - this looks simple enough to use right away. Does tables and images which is great. Thank you OrbMan.Frannie
O
4

I have had success using Siberix

http://www.siberix.com/

Corporate License: $350 USD (A single license covers unlimited number of company's developer seats, unlimited number of company's web servers and unlimited number of distributions as a part of your application.)

Ophite answered 16/1, 2009 at 20:53 Comment(2)
quimbo227 - thanks, that looks pretty good too. i'll give it a tryFrannie
Unfortunately, Siberix Technologies shut down its business on December 1st, 2014.Bombardon
L
4

Free PDF Generator .NET (WkHtmlToPdf wrapper) can generate pretty PDF from HTML template with one line of code:

var pdfBytes = (new NReco.PdfGenerator.HtmlToPdfConverter()).GeneratePdf(htmlContent);

(all you need is one DLL, no external dependencies)

Lavonnelaw answered 9/9, 2013 at 6:5 Comment(2)
I tried but its not working for .net core (v 6 in my case)Recreant
@Recreant For .NET Core/NET6 NReco.PdfGenerator.LT nuget should be used instead (LT-version is suitable for non-Windows deployments), but this build is available only for commercial users (requires a key).Lavonnelaw
M
2

I've had good experiences with Winnovative's HTML to PDF.

And bad ones with Open Source HTML Doc (Problems with form elements + CSS).

Maretz answered 16/1, 2009 at 20:57 Comment(0)
F
2

We use the Amyuni PDF Converter and have used it successfully for several years. Our usage is via the COM interface, but it does support a .NET interface.

Faeroese answered 27/10, 2010 at 14:17 Comment(0)
V
1

I have been looking for a high performing docx to pdf tool for a while now. Our system has an e-government aspect and is generating a very high number of reports to the user community. At this point, performance is paramount.

Earlier tools I have used did not do simultaneous conversion, instead each exe needed to wait for completion of the other. I have tried Aspose.words and I am very happy with the results.

First of all, it was very easy and seamless to integrate and deploy in our project. Very smooth.

Secondly, the speed of conversion is way better due to the fact that multiple jobs run in parallel.

Thirdly, not only fast, but even with no formatting errors. Considering that we are providing a multi-lingual system and some reports include both English and Arabic fields (mind right-to-left alignment!), this was very important.

And finally, the file size was quite small, which again is very important as tens of thousands of documents are created through our system.

Our first implementation was Microsoft Office Interop library. We convert docx to pdf documents by using below code. This library converts the docx documents to pdf files perfectly and we decided to upload this to report generation server. But after a while, we noticed that conversion operations are waiting for each executable. This causes a big delay on converting the documents at the same time and that's why we start to search a new tool for converting docx files to pdf files. See Image

Below code shows the how to convert docx documents to pdf files by using Aspose.Words for .NET tool. See Image 2

Vern answered 11/9, 2018 at 11:36 Comment(0)
B
0

RDLC & the Report Viewer controls can generate PDF either at the Client's discretion or at server command which can then be served as a PDF mime-type.

Braille answered 16/1, 2009 at 15:50 Comment(2)
We do this here (msdn.microsoft.com/en-us/library/ms251671(VS.80).aspx). Not too hard to use, but note that it uses SQL Server 2005 Reporting Services to do server-based generation (but not local generation).Geodetic
Server/local is a bit of a misnomer in regards to RDLC served over ASP.NET. Local generation is local to the ASP.Net application as opposed to the server generation which occurs on the SQL Server itself.Braille
Z
0

I've used PDF4NET from O2solutions with much success. They support all sorts of scenarios and digital signing of the pdf.

Zen answered 16/1, 2009 at 15:56 Comment(0)
B
0

If your data is mostly in XML, you could also look at a XSL-FO solution - we're using Alt-Soft's Xml2Pdf with great success. The "server" version is a bit of a misnomer - it's really just a single DLL you need to include in your Winforms, WPF or ASP.NET app - that's all!

Works like a charm (if you're familiar with XSLT and XSL-FO, or willing to learn it).

Marc

Behaviorism answered 16/1, 2009 at 16:2 Comment(0)
C
0

We used a set of third party DLLs from PDFSharp who in turn use DLLs from MigraDoc. I'm not privy to all the reasons that we went that direction (the decision was made by a senior developer), but I can tell you that:

  • It seems to be in active development.
  • It had most of the features we needed.
  • The source code is available. Although it used some patterns and conventions that I hadn't seen before, once I got on to them, it was fairly easy to make the changes. I added support for using the System.Drawing.Image directly rather than as saving files.
  • It is not documented well either internally or externally.
Cringe answered 16/1, 2009 at 16:23 Comment(0)
R
0

I used iTextSharp in .NET 6 as shown below, but it had an issue of loading scripts and cdn(s) for loading stylesheet, it only works with inline styles. these bytes can be saved using File.WriteAllBytes()

using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Net.Http;
using PageSize = iTextSharp.text.PageSize;

    public static byte[] GenratePdfBytes(string htmlContent)
    {
        byte[] pdfBytes;
        var pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        var html = new StringReader(htmlContent);
        var htmlparser = new HTMLWorker(pdfDoc);
        using (var memoryStream = new MemoryStream())
        {
            var writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
            pdfDoc.Open();
            htmlparser.Parse(html);
            pdfDoc.Close();
            pdfBytes = memoryStream.ToArray();
        }
        return pdfBytes;
    }
Recreant answered 27/9, 2022 at 8:24 Comment(0)
T
0

There are a few ways to do this, in my experience, and it depends on the application and complexity of what you are trying to generate and whether the resulting PDF needs to be a commercial print-ready file or just a PDF report for sharing/archiving etc, and what sort out volume output, based on budget. Most higher end PDF libraries come with a large price tag.

I have used various techniques based no the complexity, there are libraries to generate PDF (build PDF elements from the ground up) in this case you could use something like iText or others that can add content on top of a PDF.

If you need to do minor adjustments i.e. use an existing PDF as a template and add some content (text/images) there are libraries that can just stamp text and images on top. (eg: http://www.pdfsharp.net/)

If you generating invoices or reports, you could use an HTML template, merge data (replacing {tokens} etc) and then convert the html to pdf using a different type of mechanism (eg: https://www.nrecosite.com/pdf_generator_net.aspx)

There are API's if you need full control over styling, client generated templates (idml) etc, you can integrate with InDesign Server and use that to generate print ready PDF files. I have build an API like this but this is another level of PDF generation.

Trimble answered 27/9, 2022 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.