Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Applying Style Sheet In PDF

$
0
0

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());
    }




Viewing all articles
Browse latest Browse all 23244

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>