Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PDFCell width is not changing

Posted on 2013-12-08
1
Medium Priority
?
3,452 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

877 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