【问题标题】:Bold letters on iTextSharp [duplicate]iTextSharp上的粗体字母[重复]
【发布时间】:2016-02-09 15:51:19
【问题描述】:

我正在 CSharp 上编写一个简单的程序。它的作用是您编写文本(在richTextBox 中),并将其内容保存在特定路径中的.pdf 上。现在,我希望用户定位特定的单词/短语,然后单击按钮,特定的单词/短语将变为粗体。这可能吗 ??如果是,如何?

【问题讨论】:

  • 你见过这个吗? stackoverflow.com/questions/3497124/… 看起来更改字体名称可能会有所帮助
  • 我不想把所有的短语都加粗。我希望用户指定哪些单词会变粗。

标签: c# itextsharp


【解决方案1】:

首先检查一下:http://www.mikesdotnetting.com/article/81/itextsharp-working-with-fonts

基本上你需要做的是调用 SetFieldProperty 函数 你拿你的旧 pdf,编辑它,然后输出一个带有粗体文本框的新 PDF。

MemoryStream stream = new MemoryStream(); //Memory stream to with new pdf with changed bold text
PdfReader pdfReader = new PdfReader("file.pdf"); //The original PDF
PdfStamper stamper = new PdfStamper(pdfReader, stream); //A stamper to create the pdf

SetFieldProperty("fieldName","textfont",BaseFont.COURIER_BOLD,null);   //Change textbox properties

SetField("fieldName","TEXT"); //Change field text

stamper.Close(); //Save and close
byte[] newFile = stream.ToArray(); //Here you have your new file with the bolded text

此代码将为您提供一个带有粗体文本的新文件

【讨论】:

【解决方案2】:

我认为您可以将 html 输入到 itextsharp。通过这种方式,您可以使用 html 控制许多样式属性。例如:这是粗体文本。可以输入为:

This is <b>bold</b> text.

您可以像这样使用 Html 自定义文本的样式和颜色。虽然我没有尝试使用 itextsharp 使用外部样式表,但内联样式效果很好。

【讨论】:

    猜你喜欢
    • 2011-03-30
    • 2012-12-10
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    相关资源
    最近更新 更多