0
我工作出口阿拉伯語網格視圖到PDF文件,並經過百年的經驗,我終於設法解決這個問題,現在只有一個剩餘的問題,我面臨着,我不能改變寬度列,我試圖用PDFCell寬度不變
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();