Setting Properties on Images
Updating Fonts Cache
Using Aspose.PSD for Java, developers can add possibility to refresh fonts cache. Below is the code demonstration of the said functionality.
String dataDir = Utils.getDataDir(ForceFontCache.class) + "DrawingAndFormattingImages/"; | |
try (PsdImage image = (PsdImage) Image.load(dataDir + "sample.psd")) { | |
image.save(dataDir + "NoFont.psd"); | |
} | |
System.out.println("You have 2 minutes to install the font"); | |
Thread.sleep(2 * 60 * 1000); | |
OpenTypeFontsCache.updateCache(); | |
try (PsdImage image1 = (PsdImage) Image.load(dataDir + "sample.psd")) { | |
image1.save(dataDir + "HasFont.psd"); | |
} |
Setting Replacement for Missing Fonts
Using Aspose.PSD for Java, developers can replace missing fonts. Using below sample code developers will be able to set default font name when saving PSD documents as raster image (into PNG, JPG and BMP formats). This default font should be used as a replacement for all missing fonts means fonts that are not found in current Operating System. Below is the code demonstration of the said functionality.
String dataDir = Utils.getDataDir(FontReplacement.class) + "DrawingAndFormattingImages/"; | |
// Load an image in an instance of image and setting default replacement font. | |
PsdLoadOptions psdLoadOptions = new PsdLoadOptions(); | |
psdLoadOptions.setDefaultReplacementFont("Arial"); | |
try (PsdImage psdImage = (PsdImage) Image.load(dataDir + "Cloud_AzPlat_Banner3A_SB_EN_US_160x600_chinese_font.psd", psdLoadOptions)) { | |
PngOptions pngOptions = new PngOptions(); | |
psdImage.save(dataDir + "replaced_font.png", pngOptions); | |
} |