In Aspose Slides Java if you have a slides document with a invalid font or a missing font in the file in part of a paragraph the missing font it does not substitute using the substitution rules.
Sample code:
@Test
void fontReplacementMalfunctionTest() {
final String doesNotExist = "This Font Doesn't Exist";
// Instantiates Presentation
final IFontSubstRuleCollection fontSubstitutions = new FontSubstRuleCollection();
fontSubstitutions.add(
new FontSubstRule(
new FontData(doesNotExist),
new FontData("Times New Roman"),
FontSubstCondition.WhenInaccessible
)
);
Presentation pres = new Presentation();
pres.getFontsManager().setFontSubstRuleList(fontSubstitutions);
try {
// Gets the first slide in the presentation
ISlide sld = pres.getSlides().get_Item(0);
// Add AutoShape
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 100);
ITextFrame txtFrame = ashp.getTextFrame();
txtFrame.setText("Text box starting text.");
// Set font info
IParagraph paragraph = new Paragraph();
final IPortionCollection portions = paragraph.getPortions();
final IPortion portion1 = new Portion("Portion 1 ");
portion1.getPortionFormat().setLatinFont(new FontData(doesNotExist));
portions.add(portion1);
final IPortion portion2 = new Portion("Portion 2");
portion2.getPortionFormat().setLatinFont(new FontData(doesNotExist));
portion2.getPortionFormat().setFontBold(NullableBool.True);
portions.add(portion2);
txtFrame.getParagraphs().add(paragraph);
// Saves the presentation to disk
pres.save("replacementMalfunctionTest.pptx", SaveFormat.Pptx);
pres.save("replacementMalfunctionTest.pdf", SaveFormat.Pdf);
}
finally {
if (pres != null) {
pres.dispose();
}
}
}
Sample output files:
replacementMalfunctionTest.7z (57.1 KB)