Click here to Skip to main content
13,799,961 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a panel on page and inside panel have grid view when i export panel data into pdf every thing is fine but gridview height width and column height not work as per defined.
I try every thing from gridview property and code behind also.

I am using iTextSharp

What I have tried:

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            string pdfFileName = Request.PhysicalApplicationPath + "\\files\\" + "DeliveryChalan" + FileName + ".pdf";
            string appPath = HttpContext.Current.Request.ApplicationPath;
            string path = Server.MapPath(appPath + "\\files\\" + "DeliveryChalan" + FileName + ".pdf");
            dynamic output = new FileStream(path, FileMode.Create);
            iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output);
           //PdfWriter writer= iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output);
            //writer.PageEvent = new Footer();

            pdfDoc.Open();
            //Paragraph welcomeParagraph = new Paragraph("Hello, World!");
          
            //pdfDoc.Add(welcomeParagraph);

            for (int i = 1; i <= 4; i++)
            {
                string Id = "pnldata" + i;
                Panel pnl = (Panel)FindControl(Id);

                using (StringWriter sw = new StringWriter())
                {
                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                    {
                       
                        pdfDoc.SetPageSize(new Rectangle(595, 850));
                        var style = new StyleSheet();
                        style.LoadTagStyle("body", "size", "9px");
                        //style.LoadTagStyle("grdDeliverChallan2", "height", "500px");
                        htmlparser = new HTMLWorker(pdfDoc);
                        //htmlparser.SetStyleSheet(style);
                        //pdfDoc.PageSize.Height = 10;
                       
                        pdfDoc.NewPage();
                        //pdfDoc.PageSize
                        //const string V = @"vshsd";
                        //Chunk c1 = new Chunk("A chunk represents an isolated string. ");
                        //ColumnText.ShowTextAligned(writer.DirectContent, Element.ALIGN_RIGHT, V, 36, 820, 0);

                        pnl.RenderControl(hw);
                    
                        StringReader sr = new StringReader(sw.ToString());
                        htmlparser.Parse(sr);
                    }
                }
            }
           

            pdfDoc.Close();
Posted 6-Dec-18 18:54pm
Comments
ArvindTomar 2 days ago
   
after long R & D Finaly i Got the answer i use ironpdf.dll for control the height and with of grid and page

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
string appPath = HttpContext.Current.Request.ApplicationPath;
pdfDoc.Open();
Panel pnl;
StringWriter sw = new StringWriter();
for (int i = 1; i <= 5; i++)
{
string Id = "pnldata" + i;

pnl = (Panel)FindControl(Id);

using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
pdfDoc.SetPageSize(new Rectangle(595, 850));

htmlparser = new HTMLWorker(pdfDoc);



pdfDoc.NewPage();

pnl.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());
htmlparser.Parse(sr);

}
}
var Renderer = new HtmlToPdf();

string html1 = "" + sw.ToString() + "";
StringBuilder html = new StringBuilder(html1);

Renderer.PrintOptions.PaperSize = PdfPrintOptions.PdfPaperSize.A4;
Renderer.PrintOptions.PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait;
// Renderer.PrintOptions.Header = new SimpleHeaderFooter() { CenterText = "Iron PDf C# Html to PDF Example", FontSize = 10 };
// Renderer.PrintOptions.Footer = new HtmlHeaderFooter() { HtmlFragment = "page {page} of {total-pages}" };
var PDF = Renderer.RenderHtmlAsPdf(html1);
string path = Server.MapPath(appPath + "\\files\\" + "DeliveryChalan" + FileName + ".pdf");
PDF.SaveAs(path);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181214.1 | Last Updated 6 Dec 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100