I need to create a pdf file from the HTML provided from database which was stored from a editor...
i have to show the corresponding HTML with all the styles in the pdf...please help
I have uses itextsharp method but i am not getting the correct content i provided in the editor when i convert it to pdf,
Code i used
string content = "<the html content from database>";
StringReader reader = new StringReader(content);
MemoryStream ms = new MemoryStream();
Document doc = new Document(PageSize.A4,50,50,30,30);
HTMLWorker parser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc, ms);
doc.Open();
try
{
parser.Parse(reader);
}
catch(Exception ex)
{
Paragraph paragraph = new Paragraph("Error! " + ex.Message);
paragraph.SetAlignment("center");
Chunk text = paragraph.Chunks[0] as Chunk;
doc.Add(paragraph);
}
finally
{
doc.Close();
}
Byte[] buffer = ms.GetBuffer();
if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
is anything wrong in this please help with code create pdf from html