Spire.PDF 10.4.7 现已正式发布。该版本支持获取查找到的文本的字体格式,同时新增了保存文档时的进度回调接口。此外,一些在转换、加载和保存 PDF 文件时出现的问题也得已成功修复。详情请查阅以下内容。
新功能:
- 支持获取查找到的文本的字体格式。
注意:仅支持获取加粗、模拟加粗(字体样式设置填充加描边)、斜体、颜色,不支持获取下划线。 - 新增了保存文档时的进度回调接口。
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputFile);
PdfPageBase page = pdf.Pages[0];
PdfTextFinder finds = new PdfTextFinder(page);
finds.Options.Parameter = TextFindParameter.None;
List<PdfTextFragment> result = finds.Find("hello");
StringBuilder str = new StringBuilder();
foreach (PdfTextFragment find in result)
{
string text = find.LineText;
string FontName = find.TextStates[0].FontName;
float FontSize = find.TextStates[0].FontSize;
string FontFamily = find.TextStates[0].FontFamily;
bool IsBold = find.TextStates[0].IsBold;
bool IsSimulateBold = find.TextStates[0].IsSimulateBold;
bool IsItalic = find.TextStates[0].IsItalic;
Color color = find.TextStates[0].ForegroundColor;
str.AppendLine(text);
str.AppendLine("FontName: " + FontName);
str.AppendLine("FontSize: " + FontSize);
str.AppendLine("FontFamily: " + FontFamily);
str.AppendLine("IsBold: " + IsBold);
str.AppendLine("IsSimulateBold: " + IsSimulateBold);
str.AppendLine("IsItalic: " + IsItalic);
str.AppendLine("color: " + color);
str.AppendLine(" ");
}
PdfTextReplacer ptr = new PdfTextReplacer(page);
ptr.ReplaceAllText("hello", "New");
File.WriteAllText(outputFile_T, str.ToString());
pdf.SaveToFile(outputFile);
pdf.Dispose();
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputFile);
pdf.RegisterProgressNotifier(new CustomProgressNotifier());
pdf.SaveToFile(outputFile, FileFormat.XPS);
pdf.Close();
public class CustomProgressNotifier :IProgressNotifier
{
StringBuilder str = new StringBuilder();
public void Notify(float progress)
{
str.AppendLine(progress + "%");
File.WriteAllText(outputFile_txt, str.ToString());
}
}
问题修复:
- 修复了转换 PDF 文档到图片时内容丢失的问题。
- 修复了绘制含有 "∙" (unicode = 8729) 字符的文本到 PDF 页面失败的问题。
- 修复了打印转灰度后的PDF时程序抛出 System.NullReferenceException 异常的问题。
- 修复了转换灰度 PDF 文档时程序抛出 System.ArgumentNullException 异常的问题。
- 修复了用 signatureOne.VerifySignature() 验证数字签名结果不正确的问题。
- 修复了转换 XPS 文档到 PDF 文档时图片丢失的问题。
- 修复了转换 OFD 文档到 PDF 文档时程序抛出 System.NullReferenceException 异常的问题。
- 修复了加载和保存 PDF 文档后签名无效的问题。
- 修复了转换 OFD 文档到 PDF 文档时程序抛出 System.ArgumentException 异常的问题。
- 修复了查找文本时程序抛出 System.ArgumentNullException 异常的问题。
获取 Spire.PDF 10.4.7,请点击: