I have an application which have a Invoice.I am using Itextsharp dll to convert the the Invoice to PDF.I have one aspx page which contain the Text style sheet and a grid view ,But when It convert to PDF the style sheet are not applied in the pdf,All the text are printing into line by line.
I am using this code
protected void btnpdf_Click(object sender, EventArgs e) { // Create a Document object var document = new Document(PageSize.A4, 50, 50, 25, 25); // Create a new PdfWrite object, writing the output to a MemoryStream var output = new MemoryStream(); var writer = PdfWriter.GetInstance(document, output); // Open the Document for writing document.Open(); iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); hw.Style = styles; // Read in the contents of the Receipt.htm HTML template file string contents = File.ReadAllText(Server.MapPath("~/App_UI/AppAdmin/Invoice.aspx")); var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null); foreach (var htmlElement in parsedHtmlElements) document.Add(htmlElement as IElement); document.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition","attachment;filename=Receipt1.pdf"); Response.BinaryWrite(output.ToArray()); }