【问题标题】:Can't find text in PdfTable在 PdfTable 中找不到文本
【发布时间】:2012-07-20 13:03:13
【问题描述】:
BaseFont Vn_Helvetica = BaseFont.CreateFont(@"C:\Windows\Fonts\arial.ttf", 
"Identity-H", BaseFont.EMBEDDED);
Font fontNormal = new Font(Vn_Helvetica, 12, Font.NORMAL);
foreach (var t in htmlarraylist)
                {

 if (t is PdfPTable)
                    {
                        var countColumn= ((PdfPTable)t).NumberOfColumns;//is 7
                        var countRows = ((PdfPTable)t).Rows;//is 10

//我想为所有文本设置 normalFont 但 defaultCell.Phrase 始终为空

((PdfPTable)t).DefaultCell.Phrase = new Phrase() { Font = fontNormal };

//如何在pdfptable中查找文本来设置字体?

                    }
                   document.Add(t);

【问题讨论】:

标签: c# itextsharp pdfptable


【解决方案1】:

您正在尝试为表格的默认单元格设置短语的字体。您需要为表格上的所有单元格设置此项:

        // t is a PdfPTable
        foreach(var row in t.Rows)
        {
            foreach(var cell in row.GetCells())
            {
                if(cell.Phrase != null)
                {
                    cell.Phrase.Font = fontNormal;
                }
            }
        }

【讨论】:

  • 你有我可以测试的示例 PDF 吗?
  • 我通过另一种不需要在 pdfptable 中搜索文本的方法解决了我的问题,感谢您的帮助
猜你喜欢
  • 2021-11-08
  • 2015-07-21
  • 2020-07-22
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 2016-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多