mson
mson

Reputation: 7824

PDF generation in C#

We currently send an email notification in plain text or html format. Our environment is C#/.NET/SQL Server.

I'd like to know if anyone recommends a particular solution. I see two ways of doing this:

or

I'm open to third party libraries (especially if they are open source and free). It seems that SSRS is the simplest and easiest way to go. Anyone have any tips?

Upvotes: 1

Views: 1210

Answers (3)

Jan Blaha
Jan Blaha

Reputation: 3095

If you only need simple html -> pdf conversion, look at wkhtmltopdf. It's free, opensource, command line utility based on webkit.

If you want something more complex like prepare multiple templates or store history of pdf outputs. Look at reporting server jsreport

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You can use iTextSharp to convert your html pages to pdf. Here's an example:

class Program
{
    static void Main(string[] args)
    {
        string html = 
@"<html>
<head>
  <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" />
</head>
<body>
  <p style=""color: red;"">Hello World</p>
</body>
</html>";

        Document document = new Document(PageSize.A4);
        using (Stream output = new FileStream("out.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
        using (StringReader htmlReader = new StringReader(html))
        using (XmlTextReader reader = new XmlTextReader(htmlReader))
        {
            PdfWriter.GetInstance(document, output);
            HtmlParser.Parse(document, reader);
        }

    }
}

Upvotes: 4

user1976
user1976

Reputation:

iText-Sharp
Works very much like the java version, and has both great documentation and multiple books available.

Upvotes: 0

Related Questions