Solved

PDFCell width is not changing

Posted on 2013-12-08
1
2,857 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Service with UDP 2 26
Editing XSL files, 2 18
getting id from database 5 23
VB.NET HttpWebRequest 12 30
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now