locked
Convert an ASPX page to PDF format with page size settings RRS feed

  • Question

  • User993120701 posted

    Hi Friends,

    I am converting an aspx page form to PDF format while click the button.  Page width is shown very less. How can I set page width, height, margin. In PDF doc not shown as per ASPX format. Pl help on this. Its Urgent.

          protected void Button1_Click(object sender, EventArgs e)
            {

               string attachment = "attachment; filename=" + "abc" + ".pdf";
                Response.ClearContent();
                Response.AddHeader("content-disposition", attachment);
                Response.ContentType = "application/pdf";
                StringWriter s_tw = new StringWriter();
                HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
                h_textw.AddStyleAttribute("font-size", "7pt");
                h_textw.AddStyleAttribute("color", "Black");
                pnl.RenderControl(h_textw);//Name of the Panel
                // var doc = new Document(PageSize.A4, 5, 5, 10, 5);
                Document doc = new Document(new iTextSharp.text.Rectangle(900f, 1500f));
                FontFactory.GetFont("Verdana", 80, iTextSharp.text.BaseColor.RED);
                PdfWriter.GetInstance(doc, Response.OutputStream);
                doc.Open();
                StringReader s_tr = new StringReader(s_tw.ToString());
                HTMLWorker html_worker = new HTMLWorker(doc);
                html_worker.Parse(s_tr);
                doc.Close();
                Response.Write(doc);

    }

    Friday, January 30, 2015 4:24 AM

All replies

  • User454225933 posted

    i would suggest that this line of code you've commented out 

    // var doc = new Document(PageSize.A4, 5, 5, 10, 5);

    is trying to set the page size (A4) and the margins.

    why is it commented out? was it not working? what was the error?

    Friday, January 30, 2015 10:37 AM