Spire.Office for Java 11.6.0 已正式发布。本版本中,Spire.Doc for Java 增强了 Word 到 PDF 的转换功能;Spire.XLS for Java 增强了 Excel到PDF和图片的转换;Spire.PDF for Java 支持设置 PDF 阅读方向与语言。此外,本版本还成功修复了多个问题。更多详情如下。
获取 Spire.Office for Java 11.6.0,请点击:
https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
Spire.Doc for Java
问题修复:
- 修复了转换 Word 到 PDF,符号换行不正确的问题。
- 修复了更新交叉引用域不正确的问题。
- 修复了转换 Word 到 PDF,文本位置不正确的问题。
- 修复了转换 Word 到 PDF,项目符号样式不正确的问题。
Spire.XLS for Java
问题修复:
- 修复了转换 Excel 到 PDF 时分页不正确的问题。
- 修复了转换工作表到图片时程序挂起的问题。
- 修复了转换 Excel 到图片时内容被裁切的问题。
Spire.PDF for Java
新功能:
- 新增对使用 SHA-256/SHA-512 算法证书进行数字签名的支持。
- 新增在 OFD 转 PDF 时设置备用字体的支持。
- 为 OFD 转 PDF 转换新增进度回调功能。
- 支持设置PDF阅读方向与语言。
- PdfMDPSignatureMaker 新增 IPdfSignatureFormatter 重载,为 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)
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(inputFile);
pdf.getViewerPreferences().setReadingDirection(PdfReadingDirection.LeftToRight);
pdf.setLanguage("zh-CN");
pdf.saveToFile(outputFile , FileFormat.PDF);
PdfDocument document = new PdfDocument();
PdfPageBase pdfPageBase = document.getPages().add();
pdfPageBase.getCanvas().drawString("Hello, World!",
new PdfFont(PdfFontFamily.Helvetica, 30f),
PdfBrushes.getBlack(), 10, 10);
PdfCertificate certificate = new PdfCertificate(path+"gary.pfx", "e-iceblue");
PdfPKCS7Formatter formatter = new PdfPKCS7Formatter(certificate, false);
String timeStampUrl = "https://rfc3161.ai.moda/adobe";
formatter.setTimestampService(new TSAHttpService(timeStampUrl));
formatter.setOCSPService(new OCSPHttpService(null));
PdfMDPSignatureMaker signatureMaker = new PdfMDPSignatureMaker (document, formatter, PdfMDPSignatureMaker.Level2Permissions);
signatureMaker.makeSignature("signName");
com.spire.pdf.interactive.digitalsignatures.PdfSignature signature = signatureMaker.getSignature();
signature.setName("Gary");
// signature.setReason("This is the final version.");
signature.setLocation("U.S.");
signature.setContactInfo("112554");
PdfSignatureAppearance appearance = new PdfSignatureAppearance(signature);
appearance.setNameLabel("Signer: ");
// appearance.setReasonLabel("Reason: ");
appearance.setLocationLabel("Location: ");
appearance.setContactInfoLabel("Phone: ");
PdfImage image = PdfImage.fromFile(path+"logo.png");
appearance.setSignatureImage(image);
appearance.setGraphicMode(GraphicMode.SignImageAndSignDetail);
Rectangle2D rect = new Rectangle2D.Float();
rect.setFrame(new Point2D.Float(90, 550), new Dimension(150, 80));
signatureMaker.makeSignature("Signature", pdfPageBase,
(float) rect.getMinX(), (float) rect.getMinY(),
(float) rect.getWidth(), (float) rect.getHeight(),
appearance);
String output = "signature.pdf";
document.saveToFile(path+output, FileFormat.PDF);
document.close();
问题修复:
- 修复了加载 PDF 文档时未提供权限密码导致程序抛出异常的问题。
- 修复了将图片转换为 PDF 时程序抛出异常的问题。
- 修复了 PDF 转 PDF/A 后勾选符号丢失的问题。
- 修复了提取 PDF 页面文本时出现乱码的问题。
- 修复了 PDF 转 SVG 后在浏览器中显示内容错误的问题。
- 修复了验证签名有效性不准确的问题。
- 修复了绘制图片效果不正确的问题







