3

Visual Studio 2005 C# 2.0 Net でコードを書いています。Textfile と Textfile の内容を PDF ファイルで読みました。ここで、Textfile のテキスト ("---") を描画線に置き換えたいと思います。

public void PDFCreate()
{
   iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 25, 10, 40, 40);
    PdfWriter writer = PdfWriter.GetInstance(doc, fs);


    ///########
    BaseFont bf = BaseFont.CreateFont(@"C:\WINNT\Fonts\COUR.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    iTextSharp.text.Font f = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.BOLD);

    BaseFont bs = BaseFont.CreateFont(@"C:\WINNT\Fonts\COUR.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    iTextSharp.text.Font s = new iTextSharp.text.Font(bs, 10.2f, iTextSharp.text.Font.NORMAL);

    doc.Open();

    PdfContentByte cb = writer.DirectContent;

    string myfiles = MySetIniPath + feld[0] + "_rus." + feld[1];
    string str;
    StreamReader myfi = new StreamReader(myfiles);
    {
        while ((str = myfi.ReadLine()) != null)
        {
            if (str.Contains("MIMO"))
                doc.NewPage();

            if (str != "")
            {
                if (str.StartsWith("результат теста"))
                {
                    doc.Add(new Phrase(str, s));
                    doc.Add(new Phrase("\n\n", s));
                    continue;
                }
                if (str.StartsWith("Nummer"))
                {
                    doc.Add(new Phrase(str, f));
                    doc.Add(new Phrase("\n\n", f));
                    continue;
                }
                if (str.StartsWith("MIMO") ||
                    str.StartsWith("Serial") ||
                    str.StartsWith("Numbers") ||
                    str.StartsWith("order"))
                {
                    doc.Add(new Phrase(str + "\n", f));
                    continue;
                }
                if (str.StartsWith("---"))
                {
                    //Draw a line
                    continue;
                }
                doc.Add(new Phrase(str + "\n", s));
            }
        }
    }
    doc.Close();
    myfi.Close();
}

itextsharpif(str.StartsWith("----"))を使用して、またはe.Graphics.MeasureString(" ", boldFont)

4

2 に答える 2

0

string.Replace と DrawString を使用できます

var text = "----- other text";
var yourValue =e.Graphics.DrawString();//Adjust your drawstring
var result = text.Replace("-----", yourValue);
于 2012-08-31T12:51:45.187 に答える
0

それが解決策です:

  if (str.IndexOf("|") > -1)
  {
       char vertLine = '\u2502'; 
       str = str.Replace("|", vertLine.ToString());
       doc.Add(new Phrase(str + "\n", s));

       continue;
    }

    if (str.StartsWith("---"))
    {  
         char vert = '\u2500'; 
         str = str.Replace("--", vert.ToString());
         doc.Add(new Phrase(str + str +"\n", s));

          continue;
      }
于 2012-09-03T07:06:01.790 に答える