我们很高兴地宣布 Spire.PDF for Java 12.6.1 正式发布。此次更新新增了对 SHA-256/SHA-512 证书数字签名 PDF 的支持,并支持在 OFD 转 PDF 时设置备用字体。此外,本版本还修复了多个与 PDF 转换和文本提取相关的问题。 本次发布的更新内容如下
新功能:
- 新增对使用 SHA-256/SHA-512 算法证书进行数字签名的支持。
- 新增在 OFD 转 PDF 时设置备用字体的支持。
- 为 OFD 转 PDF 转换新增进度回调功能。
public static void main(String[] args) throws IOException {
// Create pdf document
PdfDocument doc = new PdfDocument();
// Load file from disk
doc.loadFromFile("Sample.docx");
// Load the X509 certificate for signature
PdfPKCS7Formatter formatter = new PdfPKCS7Formatter(new PdfCertificate("gary.pfx", "e-iceblue"), false);
// Create an instance of PdfOrdinarySignatureMaker using the loaded document and certificate
PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(doc, formatter);
// Create an instance of PdfCustomSignatureAppearance as the appearance for the signature
IPdfSignatureAppearance signatureAppearance = new PdfCustomSignatureAppearance();
// Make the signature with a specified name and the custom appearance
signatureMaker.makeSignature("Signature", signatureAppearance);
// Iterate through all hash algorithm types
for (HashAlgorithmType hashAlg : HashAlgorithmType.values()) {
// Skip SM3 (case-insensitive)
if ("SM3".equalsIgnoreCase(hashAlg.name())) {
continue;
}
try {
// Set the current hash algorithm
formatter.getProperties().setHashAlgorithm(hashAlg);
String filePath = "AddImageSignature_" + hashAlg.name() + ".pdf";
doc.saveToFile(filePath, FileFormat.PDF);
System.out.println("Succeed:" + hashAlg.name());
} catch (Exception ex) {
System.out.println("Error HashAlgorithmType:" + hashAlg.name());
System.out.println("Error Info:" + ex.getMessage());
}
}
// Close the document
doc.close();
}
// Custom signature appearance implementation
public static class PdfCustomSignatureAppearance implements IPdfSignatureAppearance {
@Override
public void generate(PdfCanvas pdfCanvas) {
// Set font size
int fontSize = 10;
// Create Arial font
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", Font.PLAIN, fontSize), true);
// Set line height
float lineHeight = fontSize;
// Draw text string
pdfCanvas.drawString("AAAAAAAAAAA", font, PdfBrushes.getRed(), new Point.Float(0, 0));
// Draw image at specified position
pdfCanvas.drawImage(PdfImage.fromFile("E-iceblue logo.png"), new Point.Float(20, 0));
}
}
OfdConverter converter = new OfdConverter(ofdFile.getAbsolutePath());
converter.getOptions().setDefaultFontName(fontName);
converter.toPdf(PdfPath);
CustomProgressNotifier progressNotifier =new CustomProgressNotifier(output_txt);
ofdConverter ofdconverter=new Ofdconverter(inputPath);
ofdconverter.registerProgressNotifier(progressNotifier);
ofdConverter.toPdf(outputPath);
CustomProgressNotifier progressNotifier2=new CustomProgressNotifier(output_txt2);
PdfToWordConverter converter=new PdfTowordConverter(inputPath2);
converter.registerProgressNotifier(progressNotifier2);
converter.saveToDocx(outputPath2)
问题修复:
- 修复了加载 PDF 文档时未提供权限密码导致程序抛出异常的问题。
- 修复了将图片转换为 PDF 时程序抛出异常的问题。
- 修复了 PDF 转 PDF/A 后勾选符号丢失的问题。
- 修复了提取 PDF 页面文本时出现乱码的问题。
- 修复了 PDF 转 SVG 后在浏览器中显示内容错误的问题。
获取 Spire.PDF for Java 12.6.1,请点击以下链接:







