pdf格式,一个字加粗

本文关键字:一个 格式 pdf | 更新日期: 2023-09-27 18:01:32

我需要想个办法把一个单词加粗。

我有一个很长的文本,需要一些粗体的单词。

File.WriteAllText("Vertrag/vertrag.txt", File.ReadAllText("Vertrag/vertrag.txt").Replace("Verstragsgegenstand",  new XFont("Verdana"mbox 7m XFontStyle.Bold) "BoldWord"); 

pdf格式,一个字加粗

您可以尝试使用chunk

string path = Server.MapPath("PDFs");
Rectangle r = new Rectangle(400, 300);
Document doc = new Document(r);
PdfWriter.GetInstance(doc, new FileStream(path + "/Blocks.pdf",     FileMode.Create));
doc.Open();
Chunk c1 = new Chunk("A chunk represents an isolated string. ");
for (int i = 1; i < 4; i++)
{
    doc.Add(c1);
}

详情见http://www.mikesdotnetting.com/article/82/itextsharp-adding-text-with-chunks-phrases-and-paragraphs

使用PDFsharp,您必须拆分文本,并单独调用DrawString以获取正常和粗体文本。

建议使用MigraDoc。您仍然需要分割文本并对粗体单词使用AddFormattedText,但是您会自动获得换行符和分页符。

问题中显示的方法(使用String.Replace)将不起作用。

参见:
http://pdfsharp.net/wiki/MigraDocHelloWorld-sample.ashx