Hello team,
I am currently using Aspose.Slides 25.5 to convert PowerPoint presentations (PPT) to PDF format. The fonts used in the PPT files are not available on the machine where the conversion is taking place. To avoid font substitution by Aspose.Slides, I have embedded the fonts in the source PPT files.
However, I have observed that Aspose.Slides still substitutes the fonts to other fonts, despite the fonts being embedded in the source PPT files. This issue needs to be addressed to ensure the accurate representation of the original fonts in the converted PDFs.
I have added below rules in code to substitute fonts only when not accessible:
IFontSubstRuleCollection slidesFontSettings = new FontSubstRuleCollection();
for (final Map.Entry<String, String> entry : substituteFontMap.entrySet()) {
final IFontSubstRule fontSubstituteRule = new FontSubstRule(new FontData(entry.getKey()),
new FontData(entry.getValue()),
FontSubstCondition.WhenInaccessible);
slidesFontSettings.add(fontSubstituteRule);
}
presentation.getFontsManager().setFontSubstRuleList(slidesFontSettings);
Thank you for your attention to this matter.
@aakanksha76,
Thank you for contacting free support. We need more information to thoroughly investigate the case. Please share the following files and information:
- The sample presentation file.
- The simplest complete code example.
- The output PDF file.
- The name and version of the operating system on which the code was executed.
- The JDK target version in your application project.
@andrey.potapov
Please find the code and sample files here:
FontEmbeddedPPT.zip (3.9 MB)
Operating System : “Rocky Linux 8.10 (Green Obsidian)”
Openjdk version : “21.0.8”
@aakanksha76,
Thank you for the details. Unfortunately, I was unable to reproduce the problem you described. Please try to isolate the problem and share step-by-step instructions on how to do this.
@andrey.potapov Can you please share the pdf generated at your side?
@aakanksha76,
This is my output file: output.pdf (16.1 KB)
@andrey.potapov Can you please confirm if Arial Narrow font is installed or not on your linux machine?
@aakanksha76,
I used the following Dockerfile:
FROM rockylinux:8
RUN dnf install -y \
java-21-openjdk-devel \
maven \
&& dnf clean all
ENV JAVA_HOME=/usr/lib/jvm/java-21
ENV PATH=$JAVA_HOME/bin:$PATH
WORKDIR /app
COPY . .
RUN mvn clean install
CMD ["java", "-cp", "target/TestApp-jar-with-dependencies.jar", "Application"]
I also checked the font using the following code:
public static void printFonts() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (java.awt.Font font : ge.getAllFonts()) {
System.out.println(font.getName());
try {
Object font2D = null;
try {
font2D = Class.forName("sun.font.FontUtilities").getDeclaredMethod("getFont2D", new Class[]{java.awt.Font.class})
.invoke(null, new Object[]{font});
} catch (Throwable ignored) {
try {
font2D = Class.forName("sun.font.FontManager").getDeclaredMethod("getFont2D", new Class[]{java.awt.Font.class})
.invoke(null, new Object[]{font});
} catch (Throwable e) {
}
}
java.lang.reflect.Field platNameField = Class.forName("sun.font.PhysicalFont").getDeclaredField("platName");
platNameField.setAccessible(true);
if (font2D != null) {
System.out.println(platNameField.get(font2D));
}
} catch (Throwable e) {
}
}
}
The output font list did not contain the Arial Narrow font.
@andrey.potapov Thank you for confirming that.
Can you please suggest if any code changes are required to use the embedded fonts in the source ppt for conversion?
We are embedding the font in source ppt but it is getting replaced by DejaVu Sans font in pdf which I attached in the zip file above. Can you help us know what could be causing the issue at our side ?
@aakanksha76,
Usually, you don’t need to force the application of fonts embedded in a presentation; they are applied automatically.
Please try the following:
-
Carefully check whether you are actually using Aspose.Slides for Java version 25.5.
-
Try using the following option:
pdfOptions.setCompliance(PdfCompliance.PdfA1a);
-
Try using FontSubstCondition.Always instead of FontSubstCondition.WhenInaccessible in your code, in case Arial Narrow is installed on the operating system anyway.
Hello,
Cannot use FontSubstCondition.Always as it will do the font substitution even if font is embedded, which is not the desired behavior.
The font gets substituted to a totallay different font than the one embedded or the one defined in font rule:
final com.aspose.slides.IFontSubstRule fontSubstituteRule = new com.aspose.slides.FontSubstRule(
new FontData("Arial Narrow"), new FontData("Liberation Sans Narrow"),
FontSubstCondition.WhenInaccessible);
It should have got substituted by Liberation Sans Narrow font as defined in code and present on machine but it gets substituted to DejaVu Sans which is unexpected.
Since this issue is reproducible at our end, can you please help us understand the possible reasons of this issue?
@aakanksha76,
It is hard to evaluate the issue since it is not reproduced on our end. Could you please confirm which Aspose.Slides for Java version you are using in your app. Also, when you try using FontSubstCondition.Always option, does it fix the issue or not? By the way, you may also try to replace fonts (instead of fonts substitution) in the Presentation before saving to PDF, see the document for your reference: Streamline Font Replacement in Presentations Using Java|Aspose.Slides Documentation
@amjad.sahi
We are using Aspose.Slides 25.5.
Using FontSubstCondition.Always does not solve the issue since it will substitute the font even if font is embedded in the ppt. We want the embedded font to be used in the pdf and substitution should only happen when font is not embedded or Inaccessible.
Same goes for replacing the font. If font is embedded in ppt we don’t want it to get replaced by other font.
Can you please check with this ppt and share output pdf:
Sample.zip (3.9 MB)
@aakanksha76,
Thanks for the PowerPoint presentation file.
I checked your PPTX file and noticed that the text uses the “3ds” font, which is available on my system. Based on the sample (Java) code you previously shared, you were substituting the “Arial Narrow” font with “Liberation Sans Narrow.” Could you please share your updated sample (Java) code? Additionally, I would appreciate it if you could provide the output PDF file generated on your end. Please note that the “Liberation Sans Narrow” font is not available on my machine, so I would be grateful if you could also share the font (.ttf) file(s). This will allow us to test your scenario/case precisely and accordingly.
Hello,
The two main issues we are encountering are:
- Font getting replaced by other fonts by aspose even if fonts are embedded in source file.
- When font not embedded in source file it should get replaced by expected font mapping provided in code, but it is again getting replaced by some other font.
These 2 issues are consistently reproduced at our side.
Could you please clarify why aspose is replacing fonts to other fonts ??
@aakanksha76,
We apologize, but we still need to reproduce the issue you mentioned on our end. As requested earlier, could you please share your complete updated sample (Java) code? Additionally, we would greatly appreciate it if you could provide the output PDF file generated on your side using your updated code. Furthermore, some fonts, such as “Liberation Sans Narrow,” are not available on my system. If possible, could you also share the font (.ttf) file(s)? This will help us test your scenario accurately and assist you more effectively.