Solved

PDFCell width is not changing

Posted on 2013-12-08
1
3,180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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