share
Stack OverflowHow do I programmatically create a PDF in my .NET application?
[+135] [45] Zack Peterson
[2008-08-01 18:37:55]
[ .net pdf ]
[ http://stackoverflow.com/questions/177/how-do-i-programmatically-create-a-pdf-in-my-net-application ] [DELETED]

Can anyone recommend a good library for programmatically creating PDF documents from within .NET applications?

(1) We use o2Solutions' PDF4net. pdf4net.com Their customer service is top-notch. - Jon DellOro
(7) This question is very useful. The q&a vote format works well. Its just bizarre to close it as not constructive. - MarkJ
(3) I agree with Mark. The moderators get hard ons when they can moderate. Unfortunate. - Greg Dean
(1) Not constructive? I'm trying to "construct" a PDF file dude! ROFL - Diego Deberdt
[+51] [2008-08-04 13:02:52] hitec

Have you looked at http://sourceforge.net/projects/itextsharp/? I have used the Java version on a project and it worked well.


iTextSharp is wonderful for this... - spinodal
(6) I managed to get to grips with this for easy to moderate PDFs very quickly (a couple of hours). Be warned though the API sucks like it was written in the 80s, but it's not a showstoper. - objektivs
Be careful with this, the syntax needs to be perfect since the error messages are terrible and offer little to resolve any syntax issues. But, it is a good tool once you get used to it. - Chris Conway
(7) The new license is a bit odd. PDFSharp is using the MIT license which is much less restrictive. - jcollum
I really hated iTextSharp when I used it so, seconded on the warning... but I wanted to move from a costly pdf creation component I previously used (which rocked though)... today I'd look for another option. - Oskar Duveborn
(14) Open Source, but with a "viral" license. You are required to make your source code open source too if you distribute your app or use it on a web server. Or alternatively pay them to be released from the license terms. Price on application :( - MarkJ
1
[+42] [2008-08-01 18:42:10] huseyint

Try PDFsharp and MigraDoc [1], it is an open source PDF creation component written in .NET

[1] http://www.pdfsharp.net/

I second this. PDFSharp is a nice tool - Vijesh VP
I use PDFsharp and more recently the 'higher level' migradoc in alot of projects - edosoft
(5) Not just open source, but with a permissive licence too: MIT. Unlike some popular competitors which require you to make your app open source. - MarkJ
hi would you pls take a look at this one ....pls stackoverflow.com/questions/6953471/… - user682417
This allows you to create PDF documents through the native GDI+ interface. - KalEl
Disappointing that PDFSharp doesn't support HTML -> PDF. (Needed to do it dynamically) - contactmatt
2
[+34] [2008-08-07 17:09:29] Haydar

I've used ITextSharp to create PDF's from .net. It is the .net port of the open source IText. It has the capability to create the PDF from scratch. But doing that would require formatting the entire document. Instead I created a PDF Form, then filled in the fields of the form using a small class. The most difficult time I had was figuring out how to get the the filled in form into the actual memory stream. The work of the class is in the following function. I can give more details if someone wants them. The sourceforge url is: http://sourceforge.net/projects/itextsharp/

  Public Function GeneratePDF() As IO.MemoryStream  
        Dim pdfTemplate As PdfReader  
        Dim stamper As PdfStamper  
        Dim tempPDF As PdfReader
        Dim doc As Document
        Dim msTemp As MemoryStream
        Dim pCopy As PdfCopy
        Dim msOutput As New MemoryStream

        pdfTemplate = New PdfReader(m_FormName)

        doc = New Document
        pCopy = New PdfCopy(doc, msOutput)
        doc.Open()

        For Each pg As FormPage In FormPages
            msTemp = New IO.MemoryStream
            pdfTemplate = New PdfReader(m_FormName)

            stamper = New PdfStamper(pdfTemplate, msTemp)

            For Each fld As FormField In pg.Fields
                stamper.AcroFields.SetField(fld.fieldName, fld.fieldValue)
            Next
            stamper.FormFlattening = True
            stamper.Close()
            tempPDF = New PdfReader(msTemp.ToArray)
            pCopy.AddPage(pCopy.GetImportedPage(tempPDF, pdfTemplate.NumberOfPages))
            pCopy.FreeReader(tempPDF)
        Next
        doc.Close()
        Return msOutput
    End Function

(2) Dont forget to set the msOutput.Position = 0 before trying to read from the stream or attach it to email. - StingyJack
3
[+21] [2008-08-05 23:58:28] rjohnston [ACCEPTED]

Just for completeness - if you represent your data in xml, you can apply an xslt to it and run it through nFOP [1], and generate a PDF that way.

[1] http://nfop.sourceforge.net/

4
[+12] [2008-09-16 22:07:23] David Negron

ComponentOne PDF™ for .NET [1]

PDFTron PDFNet SDK [2]

Essential PDF [3]

PDF4NET [4]

ExpertPDF Pdf Creator [5]

PDFTechLib [6]

PDFOne .NET [7]

Dynamic PDF [8]

PDFLib [9] - As you can see there are several vendors in this space. I think that it all depends on how you intend to integrate it in your application. For instance a few years a go I developed and application in .Net utilizing PDFLib on account that the client wanted to create a web based application that created design proofs and also provided optimization for their digital print services. Looking back at the project I wish I would have known about Dynamc PDF's suite of products [10].

[1] http://www.componentone.com/SuperProducts/PDFNET/
[2] http://www.pdftron.com/pdfnet/downloads.html
[3] http://www.syncfusion.com/products/pdf/web/default.aspx
[4] http://www.pdf4net.com/
[5] http://www.html-to-pdf.net/
[6] http://www.pdf-technologies.com/pdf-library-entedition.aspx
[7] http://www.gnostice.com/PDFOneNETOverview.asp
[8] http://www.dynamicpdf.com/
[9] http://www.pdflib.com/
[10] http://www.dynamicpdf.com/

ComponentOne PDF can't be bought separately. It's part of the ComponentOne Studio suite. - Philippe Leybaert
I've evaluated a few .NET PDF tools and thought that cete's DynamicPDF had the best documentation and easiest to use. By easy to use, I mean I barely had to look at the documentation. - jimueller
5
[+8] [2008-08-01 18:45:32] Dave Ward

I've been relatively happy with Aspose.PDF [1].

[1] http://www.aspose.com/categories/file-format-components/aspose.pdf-for-.net-and-java/default.aspx

Too expensive! Where are the cheap solutions? - Dave Haynes
6
[+8] [2008-08-04 13:21:44] mikec

There is also a product called ABCpdf [1] from a company called WebSupergoo. There's a free license available [2] as long as you link back to their site or you can buy a license and not have to link to them. I used the control for a web application which generated forms for a mortgage company and it worked very well.

[1] http://websupergoo.com/abcpdf-1.htm
[2] http://websupergoo.com/linktous.htm

(2) I've tried them all - ABCpdf is my favourite :-D - 5arx
7
[+8] [2009-07-02 14:51:58] James Hugard

I'm surprised that nobody has mentioned SQL Server Reporting Services [1].

I haven't used it in production, but it has seems to have quite a lot of nice features including a very good GUI report builder, extensibility through .NET, web services (SOAP) and web portal (WWW) interfaces, report generation on a schedule or on demand, report caching, e-mail reports (on demand or schedule) or view on-line, and can render to PDF, HTML, Excel, and Image.

[1] http://www.microsoft.com/Sqlserver/2005/en/us/reporting-services.aspx

We use it in production here since we had a base of reports already written in SSRS, gives the users a PDF of the report. - Decker97
8
[+6] [2010-03-05 02:36:34] Fadrian Sudaman

Just to be complete, often overlook You can actually use office automation and create word 2007 document and save it as PDF. If you are using older word version, you can print it to any PDF printer driver like PDFCreator or JawsPDF.


9
[+5] [2010-10-20 18:07:23] Richard B

Not sure if Zack has solidified on anything with this particular need, but I've been working on a way to render RDL files (SSRS Report Files) without the need to deploy SSRS, as I had a few applications where I needed a great reporting format (SSRS Reports), but couldn't expect the end-users to deploy and manage SSRS... Using the 2010 version of the associated libs, you can export in Word, Excel, and PDF, so this should more than fulfill your need.

You can download the source from CodePlex [1].

Word of note: I haven't gotten into subreports to-date, and am looking to do that feature at some point. If anyone is interested in tackling it, please let me know.

[1] http://ssrsviewer.codeplex.com/

10
[+5] [2010-11-10 18:04:36] mnemosyn

I'd like to mention RazorTex [1], a small project I just started [2]. It uses a very different approach than most other PDF tools suggested, I believe. Actual PDF creation happens through pdflatex. The 'views' are written using Razor.

Because of LaTeX, this is very powerful in terms of typesetting features and quality, but LaTeX has a steep learning curve. Free.

[1] http://github.com/cmenge/RazorTex
[2] http://www.emphess.net/2010/11/09/create-high-quality-pdfs-with-razor-view-engine-and-latex/

11
[+4] [2008-08-01 19:22:43] Shawn

I've been using Siberix Report Writer [1].

[1] http://www.siberix.com

12
[+4] [2008-08-03 06:41:40] Yaakov Ellis

I have used DynamicPDF [1] on a few sites, with very good results.

[1] http://www.dynamicpdf.com/

13
[+4] [2008-09-19 16:03:23] Rossen Hristov

You can also give Telerik Reporting [1] a try. It can export to PDF as well.

[1] http://www.telerik.com/products/reporting/overview.aspx

14
[+4] [2008-09-30 13:13:02] Elijah Manor

I have tried all of those programs, but none of them worked for what I was doing.

I needed to export a complicated HTML report into a PDF format.

The only tool that I found that actually rendered the report from HTML and accurately rendered it (using the CSS styles, classes, and complicated divs and tables) was a tool called Winnovative HTML to PDF Converter for .NET [1]

[1] http://www.winnovative-software.com/

15
[+4] [2008-09-30 13:16:20] Johannes

Crystal Reports can be programmed so that it outputs PDF files. Works perfect! I have developed a system that generates about 500 PDF per day for archiving. Crystal Reports even comes with Visual Studio so should be available for most. See example below:

using CrystalDecisions.CrystalReports.Engine;

ReportDocument    rptCust;
string            sDate_time;
string            sDestination_path;

CrystalDecisions.Shared.ExportOptions              myExportOptions;
CrystalDecisions.Shared.DiskFileDestinationOptions File_destination;
CrystalDecisions.Shared.PdfRtfWordFormatOptions    Format_options;

myExportOptions  = new CrystalDecisions.Shared.ExportOptions();
File_destination = new CrystalDecisions.Shared.DiskFileDestinationOptions();
Format_options   = new CrystalDecisions.Shared.PdfRtfWordFormatOptions();

sDate_time        = DateTime.Now.ToString("ddMMyyyyHHmmssff");
sDestination_path = sDestination_file + sPolicy_number + sPolicy_number1 + "-" + sDate_time + ".pdf";

File_destination.DiskFileName = sDestination_path;
myExportOptions               = rptCust.ExportOptions;

myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
myExportOptions.ExportFormatType      = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
myExportOptions.DestinationOptions    = File_destination;
myExportOptions.FormatOptions         = Format_options;

rptCust.Export();

Crystal has a bad habit of not generating PDFs in certain situations to the point where we're advising users to print to CutePDF rather than use the built in export - Rowland Shaw
@RowlandShaw: never came across this problem, even after printing over 100000 PDFs a year with this code. What situations are those you mentioned - Johannes
-1, having used CR for 6 months it would be the last thing I'd suggest. Its .NET API is horrible -- has a habit of failing to do things that are in the API. - jcollum
I've also had the issue where certain complex reports generate perfectly to the printer (printing from Crystal Reports), but when generated as a PDF the formatting of the lines goes off a bit. Getting it to work from .NET on our IIS webserver has also been a giant pain. - Shaun Mahood
16
[+4] [2011-05-22 05:33:24] Bobrovsky

Docotic.Pdf library [1] may be used to create PDFs in a .NET applications. It also can be used to extract text [2] or images from PDF files and many other things [3].

The library has no external dependencies and is written in C#.

Disclaimer: I work for Bit Miracle.

[1] http://bitmiracle.com/pdf-library/
[2] http://bitmiracle.com/pdf-library/help/extract-text.aspx
[3] http://bitmiracle.com/pdf-library/help/samples.aspx

17
[+3] [2008-09-16 06:05:28] Geir-Tore Lindsve

We're using TallPDF from TallComponents [1] and have had great success with it. Not sure what the other libraries uses, but it is using xslt as templates for the pdfs which makes it easy to adjust/update templates on a live server.

[1] http://www.tallcomponents.com/

18
[+3] [2008-09-16 21:46:01] warp

I have had good experiences with PrinceXML. It generates a .PDF from a .HTML file, which sounds like a hack at first, but their rendering engine is very good. Passes acid2 and has good .svg support so you can include vector images instead of bitmaps to keep the .PDF relatively small (which is important when generating reports which need to be sent as an attachment).

Especially if you have in-house designers who speak html/css they will have no trouble at all creating a good looking .pdf, so IMO it's a perfect match if you're doing web applications.


19
[+3] [2008-09-30 13:03:13] edosoft

I've used PDFWiter from DbAutotrack. It's dead cheap at $89 and it works like a charm See it here [1]

[1] http://www.dbautotrack.com/products/pdfwriter.html

20
[+3] [2010-01-14 01:52:59] scott

While probably overkill for the simple task of generating a PDF, ActiveReports [1] has been generating PDFs since 1996 and is a very mature PDF generator. It has many advantages over a simplistic PDF library if you need to add data to your documents, it is interesting to target formats other than PDF, or you want a visual designer. Recently in version 6, we also added advanced PDF features like digital signatures [2] and PDF timestamps [3] in addition to the existing PDF security features [4] (encryption, password, etc.).

[1] http://www.datadynamics.com/activereports
[2] http://www.datadynamics.com/Help/ActiveReports6/arConDigitalSignatures.html
[3] http://www.datadynamics.com/Help/ActiveReports6/arHOWPDFDigitalSignature.html
[4] http://www.datadynamics.com/Help/ActiveReports6/arCONPDF.html

21
[+3] [2010-04-09 02:13:43] tggagne

I've used both Syncfusion's EssentialPDF and ceTe's DynamicPDF. Each has capabilities the other does not, so which is best to use for your specific situation depends heavily on what your PDF documents must contain.


22
[+3] [2011-02-09 14:55:34] F C

EVO html to pdf [1] supports HTML5 and CSS3

[1] http://www.evopdf.com

That is pretty sweet. - Joseph Daigle
23
[+3] [2011-07-15 20:16:22] seveland

I've had good luck with the open source library PDF Clown.

http://www.stefanochizzolini.it/en/projects/clown/


24
[+2] [2008-08-01 23:20:07] Tim Boland

Here is a nice list of commercial solutions: http://www.411asp.net/home/assembly/document/pdf


25
[+2] [2008-08-04 18:44:24] Rob Allen

I've used Report .Net [1] with some success. It's free and the code makes sense to me, which is almost as important.

[1] http://sourceforge.net/projects/report/

26
[+2] [2008-08-05 23:17:24] Brad Tutterow

It would appear there is no shortage of choices.

Microsoft SQL Server Reporting Services can accomplish this [1], and exposes the functionality through an API you can code against.

[1] http://www.google.com/search?hl=en&q=reporting+services+generate+pdf+asp.net

27
[+2] [2008-09-16 16:19:09] Schnapple

Expanding on ActivePDF [1], if you have to make PDF files of Microsoft Office documents and you have a server you can install Microsoft Office on (i.e., a server in the cluster which isn't otherwise Internet connected) then ActivePDF's DocConverter [2] is almost literally the only game in town. It's pretty easy to use and has lots of .NET assemblies to work with.

[1] http://www.activepdf.com/
[2] http://www.activepdf.com/products/serverproducts/docconverter/index.cfm

28
[+2] [2008-09-17 19:38:07] Keith Maurino

I like to use GhostScript. It lets you convert PostScript files to PDF format. Plus it is free to use at no charge.


29
[+2] [2008-09-17 19:40:18] Josh Stodola

I've also used DynamicPDF and it is an excellent product. Very easy to use, and it has a very object-oriented structure. It impressed the hell out of me. It has a boatload of features, including the ability merge together multiple PDF documents.

It's not free, but I think you should check out the trial.

Regards...


30
[+2] [2008-10-10 14:35:00] Fabrizio

PdfLib [1] - The fastest library I ever used for creating pdf.

[1] http://www.pdflib.com/

31
[+2] [2008-10-10 18:12:46] jesal

I've been using iTextSharp coupled with Adobe LiveCycle Designer. Its very simple and easy to use. I have an entry on my blog about it - http://jesal.us/blog/index.php/2008/10/10/create-pdf-forms-using-itextsharp/


32
[+2] [2009-03-06 20:55:15] Stephanie

I have used Dynamic PDF with very good results thus far.


33
[+2] [2009-08-06 08:12:37] Constantine

PDF Duo .Net [1] is a small but very effective component for converting HTML to PDF.

[1] http://www.duodimension.com/html%5Fpdf%5Fasp.net/component%5Fhtml%5Fpdf.aspx

34
[+1] [2008-08-05 13:23:47] dustinupdyke

I've been using ActivePDF [1] for years and it seems to be very stable and quite powerful. Simply draw out your fields in Acrobat pro and programmatically prefill them with text, images, just about anything.

[1] http://www.activepdf.com/products/serverproducts/toolkit/index.cfm

35
[+1] [2008-08-06 07:28:44] Chris Roberts

We use DynamicPDF from CeTe (http://www.cete.com/). You can use this to either render a PDF from scratch, or pull pages of content in from an existing PDF and draw over the top.

It also has a report designer that you can use with some data binding features to help automate things a little (although I haven't actually tried that bit yet!).

It's been quite simple to use and pretty trouble-free to date.


36
[+1] [2008-08-18 17:05:50] Tom Alderman

The company that I work for is using Rubika from Solimar Systems. I believe that they also use itextsharp in there "PDFEngine". We create hundreds of pdfs with thousands of pages per month with this software.


37
[+1] [2008-08-28 21:02:12] Eric Pohl

If you're going to use iTextSharp (or its original Java incarnation, iText), you owe it to yourself to find a copy of iText In Action: Creating and Manipulating PDF [1] by Bruno Lowagie, the creator of iText. It's very well-written and contains great explanations for why PDF does things the way it does. (I have no financial interest; I just thought it was one of the better-written technical books I've read.)

[1] http://www.1t3xt.com/docs/book.php

38
[+1] [2008-09-02 17:50:25] Denis Connolly

I haven't used it myself, but I've heard good things about Prince [1]. There's a .Net interface available for it.

[1] http://www.princexml.com/overview/

39
[+1] [2008-09-05 11:09:05] Pete Gillespie

If you don't want to mess around in all the "PDF dirt" yourself then PDFTron [1] is prety good. One draw back it is not free, although it is an easy to use .Net PDF library that will get you up and running quickly.

[1] http://www.pdftron.com/

40
[+1] [2008-09-16 05:50:10] Jeremy

We're using pdftron. works. not free.


41
[+1] [2008-09-16 16:13:20] J. Peach

I highly recommend Ibex PDF Creator [1] from Visual Programming Limited. It uses standard XML:FO to create high-quality PDF documents. The libary has many features, and the vendor provides excellent support. The tool is licensed per developer so you can redistribute it without any licensing concerns.

[1] http://www.xmlpdf.com/

42
[+1] [2008-09-17 19:26:56] OrionRobillard

PDFLib - I have not found PDF feature that could not be generated using PDFLib. OTOH I have not found a PDFLib feature that I could use without reading the documentation twice.


(1) "OTOH I have not found a PDFLib feature that I could use without reading the documentation twice." Amen to that. - Oskar Austegard
43
[+1] [2011-01-24 15:30:00] Frank Rem

WebToPDF.NET [1] does a very good job at converting HTML/CSS to PDF. In fact we pass about 97% of the W3C CSS 2.1 Test Suite which is a rarely seen high conformance level amongst HTML to PDF converters (except for Prince).

Disclosure: I am affiliated with TallComponents, the vendor of the component

[1] http://www.tallcomponents.com/webtopdf1

think you mean 'Disclosure' ? - TygerKrash
44
[+1] [2011-03-08 11:39:18] Urbycoz

We use WPCubed PDF Control [1] to build our pdfs. It's very simple to use and works well. There is an evaluation version [2] available to download too.

[1] http://www.wpcubed.com/products/pdfcontrol/index.htm
[2] http://www.wpcubed.com/ftp/pdfcontroldemo.exe

45