C# PDFCell宽度未更改

C# PDFCell宽度未更改,c#,asp.net,pdf,gridview,datagridview,C#,Asp.net,Pdf,Gridview,Datagridview,我正在将阿拉伯文网格视图导出为pdf文件,经过数百次的经验,我终于解决了这个问题,现在我只剩下一个问题,我无法更改列的宽度,我尝试使用 float[] columnWidths = {2f, 1f, 1f}; table.setWidths(columnWidths); 但它也不起作用,所有的专栏都是同样大小的 iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(Grid

我正在将阿拉伯文网格视图导出为pdf文件,经过数百次的经验,我终于解决了这个问题,现在我只剩下一个问题,我无法更改列的宽度,我尝试使用

float[] columnWidths = {2f, 1f, 1f};
table.setWidths(columnWidths);
但它也不起作用,所有的专栏都是同样大小的

                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();
iTextSharp.text.pdf.PdfPTable table=new iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count);
table.RunDirection=PdfWriter.RUN\u DIRECTION\u LTR;
BaseFont bf=BaseFont.CreateFont(“c:\\\\windows\\\\fonts\\\\tahoma.ttf”,BaseFont.IDENTITY\u H,true);
iTextSharp.text.Font f2=新的iTextSharp.text.Font(bf,8,iTextSharp.text.Font.NORMAL);
for(int i=0;ifor(int i=0;i通过改变单元格宽度的位置解决了这个问题。
我将其添加到第二个循环下,读取数据列

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);

                }
        }
        //--set the columns width----
        float[] columnWidths = new float[] { 5f, 11f, 10f, 20f,15f,20f,7f,40f };
        table.SetWidths(columnWidths);
for(int i=0;i