Spire.PDF for Python 12.1.3 现已正式发布。该版本支持自定义签名外观,以及获取文本的字体样式。此外,还修复了一些在处理 PDF 文件时出现的问题。详情请查阅以下内容。
新功能:
- 提供 PdfCustomAppearance 类支持自定义签名外观。
- 支持获取文本的字体样式。
class MyPdfCustomAppearance(IPdfSignatureAppearance):
def __init__(self):
pass
def Generate(self, g: PdfCanvas):
x = 0.0
y = 0.0
fontSize = 10.0
font = PdfTrueTypeFont("SimSun", fontSize, PdfFontStyle.Regular, True)
lineHeight = fontSize
image = PdfImage.FromFile(inputImage)
g.DrawImage(image, x, y)
x = float(image.Width)
g.DrawString("Signer: Gary", font, PdfBrushes.get_Red(), PointF(x, y))
y += lineHeight + 5
g.DrawString("Phone: +86 12345678", font, PdfBrushes.get_Black(), PointF(x, y))
y += lineHeight + 5
g.DrawString("Address: Sichuan Province, China", font, PdfBrushes.get_Black(), PointF(x, y))
doc = PdfDocument()
doc.LoadFromFile(inputFile)
signatureMaker = PdfOrdinarySignatureMaker(doc, inputFile_pfx, "e-iceblue")
my_appearance = MyPdfCustomAppearance()
customAppearance = PdfCustomAppearance(my_appearance)
signatureMaker.MakeSignature("Signer", doc.Pages.get_Item(0), 90.0, 550.0, 270.0, 640.0, customAppearance)
doc.SaveToFile(outputFile)
doc.Close()
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputFile);
// 定义一个矩形
RectangleF rctg = new RectangleF(0, 0, 200, 300);
var page = doc.Pages[0];
PdfTextFinder finder = new PdfTextFinder(page);
finder.Options.Parameter = TextFindParameter.None;
finder.Options.Area = rctg;
// 再矩形中查找特定文本
List findouts = finder.FindAllText();
StringBuilder sb = new StringBuilder();
foreach (PdfTextFragment find in findouts)
{
sb.AppendLine(find.Text);
sb.AppendLine(find.TextStates[0].FontName);
sb.AppendLine(find.TextStates[0].FontSize.ToString("F2"));
}
File.WriteAllText(outputFile, sb.ToString());
问题修复:
- 修复了替换文本不正确的问题。
- 修复了在 Mac 机器上运行 Python 部分功能,程序抛出“ffi_prep_cif_var failed”的问题。
- 修复了转换 PDF 到 PDF/A2B,结果文档的内容拷贝出来不正确的问题。
- 修复了替换文本时设置了颜色,但显示效果不符合预期。
获取 Spire.PDF for Python 12.1.3 请点击:







