I am working with Asp.Net MVC 3. I have some html content in db. This content contains some images. I am trying to generate pdf. Texts are okay. However I am failing to retrieve images. I tried different apps such as Rotativa, ITextSharp etc.
Rotativa works fine on local, however on prod. server it's failing. I have no permission to install Rotativa on prod.
I searched during weeks and ITextSharp works fine. However can' t retrieve images. Just publish the text. Is there any way to publish Html content with all elements(tables, images etc.)
<pre lang="c#">
<pre> public byte[] GetPDF(string pHTML)
{
byte[] bPDF = null;
MemoryStream ms = new MemoryStream();
TextReader txtReader = new StringReader(pHTML);
Document doc = new Document(PageSize.A4, 25, 25, 25, 25);
PdfWriter oPdfWriter = PdfWriter.GetInstance(doc, ms);
Dictionary<string, object> interfaceProps = new Dictionary<string, object>() {
{"img_provider", new CustomItextImageProvider()}
};
HTMLWorker htmlWorker = new HTMLWorker(doc);
htmlWorker.InterfaceProps = interfaceProps;
doc.Open();
htmlWorker.StartDocument();
htmlWorker.Parse(txtReader);
htmlWorker.EndDocument();
htmlWorker.Close();
doc.Close();
bPDF = ms.ToArray();
return bPDF;
}
public void DownloadPDF(int Id = 0)
{
var report= _report.Select(Id);
string HTMLContent = "";
HTMLContent +=
"<div style=text-align:center; width:60%;'><h2>" + report.Heading+ "</h2></div>" +
"<br/><br/><br/><br/>" +
"<p>" + report.Content+ "</p>" +
"<center>Center this text!</center>";
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + "PDFfile.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(GetPDF(HTMLContent));
Response.End();
What I have tried:
1- Searched on the web during 15 days.
2- Read more and more content.
3- Asked to friends.
4- Drunk more coffee.
5- Didin' t sleep 3 days.