Solved

PDFCell width is not changing

Posted on 2013-12-08
1
3,126 Views
Last Modified: 2013-12-09
Hi, i working on export ¿Arabic grid view to pdf file, and after hundred of Experiences i finally managed to solve the issue, there are now only one remaining issue i am facing, i can not change the width of the columns, i tried to use
    float[] columnWidths = {2f, 1f, 1f};
    table.setWidths(columnWidths);

Open in new window


but also its not working, all he column coming in equal sizes

                     
  iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count);

            table.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
            BaseFont bf = BaseFont.CreateFont("c:\\\\windows\\\\fonts\\\\tahoma.ttf", BaseFont.IDENTITY_H, true);
            iTextSharp.text.Font f2 = new iTextSharp.text.Font(bf, 8, iTextSharp.text.Font.NORMAL);
                            
            for (int i = 0; i < noOfColumns; i++)
            {
                Phrase ph = null;
               
                if (GridView1.AutoGenerateColumns)
                {
                    ph = new Phrase(tbl.Columns[i].ColumnName, FontFactory.GetFont("Tahoma", 8, iTextSharp.text.Font.BOLD));
                }
                else
                {
                    ph = new Phrase(GridView1.Columns[i].HeaderText, FontFactory.GetFont("Tahoma", 8, iTextSharp.text.Font.BOLD));
                }
                PdfPCell clHeader = new PdfPCell(ph);
                clHeader.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#e9e9e9"));
                
                table.AddCell(clHeader);                
            }
            
            for (int i = 0; i <= GridView1.Rows.Count-1; i++)
            {
                    for (int j = 0; j <= GridView1.Columns.Count - 1; j++)
                    {
                        string cellText = Page.Server.HtmlDecode(GridView1.Rows[i].Cells[j].Text);
                        iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(100, cellText, f2));                       
                        table.AddCell(cell);
                        
                    }
            }

            
            PdfWriter.GetInstance(document, Page.Response.OutputStream);
            document.Open();
            document.SetMargins(0, 0, 0, 0);

            document.Add(table); // add the table

            document.Close();
            Page.Response.ContentType = "application/pdf";
            Page.Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
            Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Page.Response.Write(document);
            Page.Response.End();

Open in new window


any suggestion ??
0
Comment
Question by:AZZA-KHAMEES
1 Comment
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 39707548
Hi,

You shouldn't be giving the width's in Floats instead try giving with integers!

http://stackoverflow.com/questions/9208482/how-to-set-the-cell-width-in-itextsharp-pdf-creation

If you wish to give in percentages - http://stackoverflow.com/questions/1481139/itextsharp-table-width-100-of-page

Hope it helps u...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question