gpt4 book ai didi

c# - 如果行 "---",如何用 itextsharp 画一条线?

转载 作者:行者123 更新时间:2023-11-30 18:37:47 32 4
gpt4 key购买 nike

我使用 Visual Studio 2005 C# 2.0 Net 编写代码。我在 PDF 文件中读取了一个文本文件和文本文件的内容。现在我想用画线替换文本文件中的文本(“---”)。

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();
}

我如何编写(REPLACE) if(str.StartsWith("----")) 使用 itextsharp 或使用 e.Graphics.MeasureString("", boldFont)

最佳答案

您可以使用 string.Replace 和 DrawString

var text = "----- other text";
var yourValue =e.Graphics.DrawString();//Adjust your drawstring
var result = text.Replace("-----", yourValue);

关于c# - 如果行 "---",如何用 itextsharp 画一条线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12214529/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com