Generate PDF
We are currently sending email notification in plain text or html format. Our environment is C # /. NET / SQL Server.
I would like to know if anyone recommends a specific solution. I see two ways to do this:
- dynamically convert current email to pdf using third party library and send PDF as attachment
or
- use SSRS to allow users to export the pdf report (SSRS reports may eventually be transferred)
I am open to third party libraries (especially if they are open source and free). It looks like SSRS is the simplest and easiest way. Anyone have any hints?
+1
source to share
4 answers
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);
}
}
}
+4
source to share
iText-Sharp
Works very similar to the java version and has both excellent documentation and several books available.
0
source to share