Solved

PDFCell width is not changing

Posted on 2013-12-08
1
3,023 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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