We're pleased to announce the release of Spire.PDF for Android via Java 10.8.7. This version adds support for signing with certificates that use algorithms such as SHA-256 and SHA-512, as well as tracking conversion progress through progress callbacks. It also adjusts the namespace of OfdConverter. More details are listed below.
Here is a list of changes made in this release
| Category | ID | Description |
| New Feature | - | Added support for signing with certificates that use algorithms such as SHA-256/SHA-512.
PdfDocument doc = new PdfDocument();
//Load file from disk
doc.loadFromFile(inputFile);
// Load the X509 certificate for signature.
PdfPKCS7Formatter formatter = new PdfPKCS7Formatter(new PdfCertificate(inputFile_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);
for (HashAlgorithmType hashAlg : HashAlgorithmType.values()) {
if ("SM3".equalsIgnoreCase(hashAlg.name()))
{
continue;
}
// Set the current hash algorithm
formatter.getProperties().setHashAlgorithm(hashAlg);
String filePath = outputFile + "AddImageSignature_" + hashAlg.name() + ".pdf";
doc.saveToFile(filePath, FileFormat.PDF);
}
doc.close();
}
public static class PdfCustomSignatureAppearance implements IPdfSignatureAppearance {
public void generate(PdfCanvas pdfCanvas) {
int fontSize = 10;
PdfTrueTypeFont font = new PdfTrueTypeFont("Arial", 0,10, true);
float lineHeight = fontSize;
pdfCanvas.drawString("AAAAAAAAAAA", font, PdfBrushes.getRed(), 0, 0);
pdfCanvas.drawImage(PdfImage.fromFile(ExStoragePath + "data/E-logo.png"), 20, 0);
}
}
|
| New Feature | - | Added support for obtaining conversion progress via progress callback when converting PDF to Word, OFD to PDF, etc.
// Register a progress notifier when saving a PDF document
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(inputFile);
pdf.registerProgressNotifier(new CustomProgressNotifier(outputFile_T));
pdf.saveToFile(outputFile, FileFormat.XPS);
pdf.dispose();
// Register a progress notifier when converting PDF to Word
PdfToWordConverter converter = new PdfToWordConverter(inputFile);
converter.registerProgressNotifier(new CustomProgressNotifier(outputFile_T));
converter.saveToDocx(outputFile);
// Register a progress notifier when converting OFD to PDF
OfdConverter ofdConverter = new OfdConverter(inputFile);
ofdConverter.registerProgressNotifier(new CustomProgressNotifier(outputFile_T));
ofdConverter.toPdf(outputFile);
// Custom progress notifier, receives the progress in percent
public class CustomProgressNotifier implements IProgressNotifier {
private String outputFile;
private StringBuilder str = new StringBuilder();
public CustomProgressNotifier(String outputFile) {
this.outputFile = outputFile;
}
@Override
public void notify(float progress) {
str.append("Progress: ").append(progress).append("%\n");
try {
Files.writeString(Paths.get(outputFile), str.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
| Adjustment | - | The namespace of OfdConverter has been adjusted from com.spire.pdf.conversion to com.spire.additions.Ofd. |
Click the link below to download Spire.PDF for Android via Java 10.8.7: