Pregunta

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

//I want set normalFont for all the text but defaultCell.Phrase is always null

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

//how to find text in pdfptable to set the font?

                    }
                   document.Add(t);
¿Fue útil?

Solución

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;
                }
            }
        }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top