Browse our Products
Aspose.Slides for Android via Java 20.5 Release Notes
Key | Summary | Category |
---|---|---|
SLIDESANDROID-239 | Use Aspose.Slides for Java 20.5 features | Enhancement |
Public API Changes
Digital Signature in PowerPoint
Digital certificate is used to create a password-protected PowerPoint presentation, marked as created by a particular organization or person. Digital certificate can be obtained by contacting an authorized organization - a certificate authority. After installing digital certificate into the system, it can be used to add a digital signature to the presentation via File -> Info -> Protect Presentation:
The presentation may contain more than one digital signatures. After the digital signature is added to the presentation, a special message will appear in the PowerPoint:
To sign a presentation or check the authenticity of presentation signatures, Aspose.Slides API provides IDigitalSignature interface, IDigitalSignatureCollection interface and IPresentation.getDigitalSignatures() method. Currently, digital signatures are supported for PPTX format only.
Add digital signature from PFX Certificate
The code sample below demonstrates how to add a digital signature from a PFX certificate:
Open PFX file and pass the PFX password to DigitalSignature object.
Add a created signature to the presentation object.
Presentation pres = new Presentation();
try {
// Create DigitalSignature object with PFX file and PFX password
DigitalSignature signature = new DigitalSignature("testsignature1.pfx", "testpass1");
// Comment new digital signature
signature.setComments("Aspose.Slides digital signing test.");
// Add digital signature to presentation
pres.getDigitalSignatures().add(signature);
// Save presentation
pres.save("SomePresentationSigned.pptx", SaveFormat.Pptx);
} finally {
if (pres != null) pres.dispose();
}
Now its possible to check if the presentation was digitally signed and has not been modified:
// Open presentation
Presentation pres = new Presentation("SomePresentationSigned.pptx");
try {
if (pres.getDigitalSignatures().size() > 0)
{
boolean allSignaturesAreValid = true;
System.out.println("Signatures used to sign the presentation: ");
// Check if all digital signatures are valid
for (IDigitalSignature signature : pres.getDigitalSignatures())
{
System.out.println(signature.getComments() + ", "
+ signature.getSignTime().toString() + " -- " + (signature.isValid() ? "VALID" : "INVALID"));
allSignaturesAreValid &= signature.isValid();
}
if (allSignaturesAreValid)
System.out.println("Presentation is genuine, all signatures are valid.");
else
System.out.println("Presentation has been modified since signing.");
}
} finally {
if (pres != null) pres.dispose();
}
IDigitalSignatureCollection interface and DigitalSignatureCollection class have been added
DigitalSignatureCollection class has been added. It implements IDigitalSignatureCollection interface and represents a collection of digital signatures that were used or will be used to sign the presentation.
IDigitalSignatureCollection declaration:
/**
* <p>
* Represents a collection of digital signatures attached to a document.
* </p>
*/
public interface IDigitalSignatureCollection extends IGenericCollection<IDigitalSignature>
{
/**
* <p>
* Returns the signature by index.
* </p>
*/
public IDigitalSignature get_Item(int index);
/**
* <p>
* Adds the signature at the end of collection.
* </p>
* @param digitalSignature Signature to add.
*/
public void add(IDigitalSignature digitalSignature);
/**
* <p>
* Removes the signature at the specified index.
* </p>
* @param index Index of the signature that should be deleted.
*/
public void removeAt(int index);
/**
* <p>
* Removes all signatures from collection.
* </p>
*/
public void clear();
}
Please see this note for code samples.
IDigitalSignature interface and DigitalSignature class have been added
DigitalSignature class has been added. It implements IDigitalSignature interface and stores information about digital signature based on certificate used or will be used to sign the presentation.
IDigitalSignature declaration:
/**
* <p>
* Digital signature in signed file.
* </p>
*/
public interface IDigitalSignature
{
/**
* <p>
* Certificate object that was used to sign the document.
* Read-only {@link byte[]}.
* </p>
*/
public byte[] getCertificate();
/**
* <p>
* If this digital signature is valid and the document has not been tampered with, this value will be true.
* Read-only {@code boolean}.
* </p>
*/
public boolean isValid();
/**
* <p>
* The time when the document was signed.
* Read-only {@link java.util.Date}.
* </p>
*/
public java.util.Date getSignTime();
/**
* <p>
* The purpose of signature.
* Read/write {@link String}.
* </p>
*/
public String getComments();
public void setComments(String value);
}
Please see this note for code samples.
IPresentation.getDigitalSignatures() method has been added
getDigitalSignatures() method has been added to IPresentation interface and Presentation class. It allows to access a collection of digital signatures which have been used to sign or add digital signatures which will be used to sign the presentation.
Method declaration:
/**
* <p>
* Returns the collection of signatures used to sign the presentation.
* Read-only {@link IDigitalSignatureCollection}.
* </p>
*/
public final IDigitalSignatureCollection getDigitalSignatures()
Please see this note for code samples.
Check a Write Protection Password via IPresentationInfo interface
isWriteProtected() and checkWriteProtection() methods have been added to IPresentationInfo interface and PresentationInfo class. These methods allow checking whether a presentation is protected by a password to modify. The password to modify is intended to set write protection on the presentation. Write protection restricts the ability to save the presentation to the same path using host applications.
isWriteProtected() and checkWriteProtection() declarations:
/**
* <p>
* Gets a value that indicates whether a binded presentation is write protected.
* </p>
* If the presentation is protected by a password to open, the property value equals NotDefined.
* See {@link NullableBool} enumeration.
*/
public byte isWriteProtected();
/**
* <p>
* Checks whether a password to modify is correct for a write protected presentation.
* </p>
* @return
* True if the presentation is write protected and the password is correct. False otherwise.
* @exception InvalidOperationException
* If a presentation is protected by a password to open or format does not support write protection
* @param password The password to check.
* <p>
* 1. You should check the {@code IsWriteProtected}({@link #isWriteProtected}) property before calling this method.
* 2. When password is null or empty, this method returns false.
* </p>
*/
public boolean checkWriteProtection(String password);
Example
The example below demonstrates how to check a password to modify a presentation:
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(presentationFilePath);
boolean isWriteProtectedByPassword = info.isWriteProtected() == NullableBool.True && info.checkWriteProtection("my_password");
Check a Write Protection Password via IProtectionManager interface
checkWriteProtection() method has been added to the IProtectionManager interface and ProtectionManager class. This method allows checking whether a presentation is protected by a password to modify. The password to modify is intended to set write protection on the presentation. Write protection restricts the ability to save the presentation to the same path using host applications.
Method declaration:
/**
* <p>
* Determines whether a presentation is a password protected to modify.
* </p>
* @return True if the password is valid; otherwise, false.
* @param password The password for checking.
* <p>
* 1. You should check the {@code isWriteProtected}({@link #isWriteProtected}) method before calling this method.
* 2. When the password is null or empty, this method returns false.
* </p>
*/
public boolean checkWriteProtection(String password);
Example
The example below demonstrates how to check a password to modify a presentation:
Presentation presentation = new Presentation(presentationFilePath);
try {
boolean isWriteProtected = presentation.getProtectionManager().checkWriteProtection("my_password");
} finally {
if (presentation != null) presentation.dispose();
}
Check Open Protection of Presentation via IPresentationInfo interface
isPasswordProtected() method has been added to IPresentationInfo interface and PresentationInfo class. This property allows checking whether a presentation is protected to open. The presentation has protection to open when a password is set to the document.
Method declaration:
/**
* <p>
* Gets a value that indicates whether a binded presentation is protected by a password to open.
* </p>
*/
public boolean isPasswordProtected();
Example
The example below demonstrates how to check protection to open:
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(presentationFilePath);
if (info.isPasswordProtected())
{
System.out.println("The presentation '" + presentationFilePath + "' is protected by password to open.");
}
Support of Shapes Alignment has been added
The feature helps to change the placement of selected shapes on the slide. Aligns shapes to the margins or the edge of the slide or align them relative to each other.
To provide options from the picture above has been added overloaded method SlideUtil.alignShapes() and ShapesAlignmentType class.
ShapesAlignmentType
The ShapesAlignmentType determines the way to align shapes. Possible values of ShapesAlignmentType: AlignLeft, AlignRight, AlignCenter, AlignTop, AlignMiddle, AlignBottom, DistributeHorizontally, DistributeVertically.
Method SlideUtil.alignShape()
The method changes the placement of selected shapes on the slide. Input parameters:
- ShapesAlignmentType alignmentType - determines which type of alignment will be applied.
- boolean alignToSlide- if true, shapes will be aligned relative to the slide edges, otherwise shapes will be aligned relative to each other.
- IBaseSlide slide - parent slide.
- int[] shapeIndexes - indexes of shapes to be aligned.
- IShapeCollection shapes - collection of shapes to be aligned.
Example 1
Let’s say we want to align shapes with indexes 1, 2 and 4 along the top border of the slide.
Solution
Presentation pres = new Presentation("example.pptx");
try {
ISlide slide = pres.getSlides().get_Item(0);
IShape shape1 = slide.getShapes().get_Item(1);
IShape shape2 = slide.getShapes().get_Item(2);
IShape shape3 = slide.getShapes().get_Item(4);
SlideUtil.alignShapes(ShapesAlignmentType.AlignTop, true, pres.getSlides().get_Item(0), new int[]
{
slide.getShapes().indexOf(shape1),
slide.getShapes().indexOf(shape2),
slide.getShapes().indexOf(shape3)
});
} finally {
if (pres != null) pres.dispose();
}
Example 2
Another option shows how to align entire collection of shapes on the slide:
Presentation pres = new Presentation("example.pptx");
try {
SlideUtil.alignShapes(ShapesAlignmentType.AlignBottom, false, pres.getSlides().get_Item(0).getShapes());
} finally {
if (pres != null) pres.dispose();
}