When attempting to embed a TTF font in a Powerpoint presentation (pptx) using Aspose, the FontsLoader.loadExternalFont
throws an exception:
Input: input.pptx
Fonts: [Zapfino.ttf, Bradley Hand.ttf, Gurmukhi MT.ttf]
Exception:
- Caused by: com.aspose.slides.exceptions.FileNotFoundException: File not found —> File not found
- Caused by: com.aspose.slides.exceptions.FileNotFoundException: File not found —> Font name not found
Product: Aspose.Slides
version: [20.1, 20.5]
Code: Powerpoint.java
All files are in the attached assets.zip:
assets.zip (658.4 KB)
@kurtosys,
I have observed the issue shared by you and a ticket with ID SLIDESJAVA-38124 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
@kurtosys,
We have worked over the issue. This exception occurs because the array (fontData) contains invalid data (str. 332 in Powerpoint.java).
byte [] fontData = getCustomFont(fontName);
The FontsLoader is trying to create a temporary file from ‘fontData’, but since this array is corrupted, this attempt fails with an exception. Can you please verify the segment of code in ‘getCustomFont(fontName)’ method or please provide us code for getCustomFont() method in Powerpoint.java.
@mudassir.fayyaz
See the below code snippet for the getCustomFont method:
protected byte[] getCustomFont(String s3Key) {
try {
System.out.println("Attempting to fetch custom font Fonts/" + s3Key);
InputStream fontStream = this.storage.getObject("Fonts/" + s3Key);
return Utils.getBytes(fontStream);
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
Here is the code for the this.storage.getObject: (other methods in this function are from the AWS s3 lib)
public InputStream getObject(String key) {
S3Object object = s3.getObject(bucket, key);
return object.getObjectContent();
}
And the Utils.getBytes:
public static byte[] getBytes(InputStream is) throws Exception {
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
int n;
while ((n = is.read(buffer, 0, buffer.length)) != -1) {
baos.write(buffer, 0, n);
}
return baos.toByteArray();
}
@kurtosys,
Thank you for sharing requested information. We will share feedback with you as soon as issue will be addressed.
The issues you have found earlier (filed as SLIDESJAVA-38124) have been fixed in this update.