Reputation: 27931
ASP.NET / Mono MVC2 application is used to create and mail invoices, orders and other documents in PDF format.
Every customer needs different document layout and logos in document.
This layout should easily customized.
How to implement this using free software ? There should be report generator or something in application and way to create pdf files with logos from designed layouts.
Upvotes: 1
Views: 2307
Reputation: 2139
I have the same need and have really struggled to find an ideal solution for this. I am currently using iTextSharp, which seems to be a popular choice. It lets you render an html page as a pdf. I've found that it has limited support for css styles, which can make it frustrating to get exactly what you want. Here's some sample code of how to use this in mvc:
public ActionResult CreatePdfFromView(YourType yourViewData)
{
var htmlViewRenderer = new HtmlViewRenderer();
string htmlText = htmlViewRenderer.RenderViewToString(this, "YourViewName", yourViewData);
byte[] renderedBuffer;
using (var outputMemoryStream = new MemoryStream())
{
using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, outputMemoryStream);
writer.CloseStream = false;
document.Open();
iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(Server.MapPath("/Content/img/Your_Logo.png"));
pic.ScaleToFit(190, 95);
pic.SetAbsolutePosition(200, 730);
document.Add(pic);
try
{
StringReader sr = new StringReader(htmlText);
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, sr);
}
catch (Exception e)
{
throw;
}
}
renderedBuffer = new byte[outputMemoryStream.Position];
outputMemoryStream.Position = 0;
outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
}
return new BinaryContentResult(renderedBuffer, "application/pdf");
}
I would say make sure to use the XMLWorkerHelper instead of the HTMLWorker. I think you have to download the XML worker separately. Here is a link to the download page..
Another one that I have used, more for creating excel reports is DoodleReport. It's much more simple. Basically a tabular data dump. Not sure if you can do icons either.
Hope that helps. Curious to see if anyone has better suggestions.
Upvotes: 1