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

1 回答 1

1

You are trying to set the font on the phrase for the default cell of the table. You need to set this for all cells on the table:

        // t is a PdfPTable
        foreach(var row in t.Rows)
        {
            foreach(var cell in row.GetCells())
            {
                if(cell.Phrase != null)
                {
                    cell.Phrase.Font = fontNormal;
                }
            }
        }
于 2012-07-20T14:15:51.053 回答