Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为pdf表C中的行指定字体#_C#_Pdf_C# 4.0_Itext - Fatal编程技术网

C# 为pdf表C中的行指定字体#

C# 为pdf表C中的行指定字体#,c#,pdf,c#-4.0,itext,C#,Pdf,C# 4.0,Itext,当我编写if((r[3])==“0”)的条件时,即使r[3]的值等于“0”,它也会给出红色字体。有人能帮我吗?看来r[3]不是字符串类型。你要做的是: iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 8); iTextSharp.text.Font redfont = iTextSharp.text.FontFactory.GetFont(FontFactory.HE

当我编写
if((r[3])==“0”)
的条件时,即使
r[3]
的值等于“0”,它也会给出红色字体。有人能帮我吗?

看来r[3]不是字符串类型。你要做的是:

iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 8);

iTextSharp.text.Font redfont = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 8, iTextSharp.text.Color.RED);

//here I am adding that font for values in a pdf table
foreach (DataRow r in dt.Rows)
        {
            if (dt.Rows.Count > 0)
            {
                table.AddCell(new Phrase(r[0].ToString(), font5));
                table.AddCell(new Phrase(r[1].ToString(), font5));
                table.AddCell(new Phrase(r[2].ToString(), font5));
                if((r[3])=="0")------------------------------------------//
                table.AddCell(new Phrase(r[3].ToString(), font5));
                else
                    table.AddCell(new Phrase(r[3].ToString(), redfont));
                table.AddCell(new Phrase(r[4].ToString(), font5));


            }
        } document.Add(table);
if(r[3].ToString()=="0")