Font Substitution

Hi,

I am trying to save a pptx file in pdf format.
I am seeing incorrect fonts in pdf file. In order to get the information about font substitution, I enabled warning callbacks font substitution. I got following messages at console.

1. Font will be substituted from Calibri to {SansSerif}
2. Font will be substituted from Calibri to {SansSerif}
3. Font will be substituted from Arial to {SansSerif}
4. Font will be substituted from MS Gothic to {SansSerif}
5. Font will be substituted from Gulim to {SansSerif}
6. Font will be substituted from Arial Unicode to {SansSerif}
7. Font will be substituted from Calibri to {ArialMS GothicGulimArial Unicode}


I observed that Aspose is relying on Java for handling the font substitution and you can notice that font “Calibri” is substituted to {SansSerif} at line 1 and 2 but at line 7, it got replaced by {ArialMS GothicGulimArial Unicode}. Why is it so? Why do not we have one to one mapping for fonts. Why its replacing calibri to some font at some place and to some other font at another place.

Thanks
Praneeth

Hi Praneeth,

Thank you for the details.

Please share your template presentation file and sample code with us to reproduce and further investigate the issue at our end. We will check it and get back to you.

Thanks & Regards,

Hi,


The sample presentation is attached with this post and the code we are using is given below:

class PptToPdf
{
public static void main(String args[])
{
LoadOptions lo = new LoadOptions();
lo.setWarningCallback(new HandleFontsWarnings());
String fileName = “RP_Overview.pptx”;
Presentation pres = new Presentation(fileName, lo);

System.out.println(“Converting Ppt to Pdf”);
pres.save(“PPTConverted.pdf”, com.aspose.slides.SaveFormat.Pdf);


}
}

class HandleFontsWarnings implements IWarningCallback
{
public int warning(IWarningInfo warning)
{
// System.out.println(warning.getWarningType()); // 1 - WarningType.DataLoss
System.out.println(warning.getDescription()); // “Font will be substituted from X to Y”
return ReturnAction.Continue;
}
}

We are running code at linux machine.

The machine details are given below:

Oracle Linux 5 (Intel 64-bit, Developer)


OS: Oracle Linux Server release 5.8


Architecture: x86_64

RAM Details:
total used free shared buffers cached
Mem: 15600 10397 5202 0 778 5612
-/+ buffers/cache: 4007 11592
Swap: 10047 60 9986


I am also attaching the warning call back messages generated for font substitution.

Please find the attachments.

Please let me know if you require more information.

Thanks
Praneeth

Hi Praneeth,

Thank you for the details.

I checked the issue on my Windows 8 environment and I am unable to reproduce the issue using your template file. I will further test the issue over the Linux environment and will get back to you with results.

Thanks & Regards,

Hi Owais,


Do we have any update on this?



Thanks,
Praneeth

Hi Paraneeth,

I suggest you to please visit this thread post and confirm that if you are using correct JDK version on your end. Owais is also looking further in this issue and we will share the feedback with you ASAP.

Also, Aspose.Slides offers the explicit font replacement as well rule based fonts replacement. You can use the specified technique to set your own rules for font replacement. I hope this will be really helpful.

Many Thanks,

Hi,


I am using a presentation with Asian Fonts. When the presentation is rendered in pdf format then some warning callbacks are generated for font substitution.

e.g. Font will be substituted from HY???M to {BatangTimes New Roman}

How can we get the correct font for HY???M


The presentation and the warning callback messages are attached with this mail.

Note: I am running the code at linux box.

The code is given below:



public static Presentation createPresentation(byte[] inputDoc) {
Validate.notNull(inputDoc, “Could not create a Presentation object with null byte array for doc”);

final InputStream inputStream = new ByteArrayInputStream(inputDoc);

try {
LoadOptions lo = new LoadOptions();
lo.setWarningCallback(new HandleFontsWarnings());
Presentation ppt = new Presentation(inputStream, lo);
return ppt;
} finally {
StreamUtils.closeQuietly(inputStream);
}
}


public static void convertToPdf(byte[] inputDoc, String PdfFileName) {
Validate.notNull(inputDoc, “Could not create a Presentation object with null byte array for doc”);
Presentation ppt = createPresentation(inputDoc);
IFontData font[] = ppt.getFontsManager().getFonts();
System.out.println("font length: "+font.length);
for (int i = 0; i < font.length; i++) {
System.out.println("Font Name: " + font[i].getFontName());
}
ppt.save(PdfFileName, SaveFormat.Pdf);

}


One more question, When I try to get the fonts used in presentation using the API given below
ppt.getFontsManager().getFonts()…I get an empty array. Why is it returning empty array?



Thanks
Praneeth


Hi Praneeth,

I have tired using Aspose.Slides for Java 15.1.0 on my end and have observed that Aspose.Slides load all the fonts by using pres.getFontsManager().getFonts() method. It gave me correct number of fonts. I suggest you to please try using the specified version in this regard. In the mean time you can get proper font name by using following sample code.

Presentation pr = new Presentation(path + “ModifiedKoreanPpt.pptx”);
int count=pr.getFontsManager().getFonts().length;
IFontData[] data=pr.getFontsManager().getFonts();
System.out.println(data[2].getFontName());


As far as issue of improper font name, HY???M appearing in warning description is concerned, I have created an issue with ID SLIDESJAVA-34736 in our issue tracking system to further investigate and resolve the issue.

I have also added a new ticket with ID SLIDESJAVA-34737 for the issue of different font substitution offered by Aspose.Slides for same font appearing on different slides. We will investigate this on our end to see if it is really an issue or not.

This thread has been linked with both issues so that you may be automatically notified once the issues will be resolved.

Many Thanks,

Hi,

Could you please explain me the format of warning callback messages generated for font substitution?

Warning description is of form: "Font will be substituted from X to Y"

Could you please tell me what does X stand for?
Is this the font used in presentation but not registered with Java Runtime or something else??
What does Y stand for?
Is this the font selected by Aspose font substitution algorithm for replacing the missing font?

Thanks
Praneeth

Hi Praneeth,

The X mean the font that is used in presentation but unavailable in your machine or not registered in JVM and neithed called using LoadExternalFonts(). The Y is the font that is available in your machine and is visible to Aspose.Slides via JVM registered fonts or LoadExternalFonts() method. Aspose.Slides algorithm substitute missing/inaccessible font X with visible/accessible font Y.

I hope this will clear the concept to you.

Many Thanks,

Hi,



We are loading custom fonts from external directory using FontLoader.loadExternalFonts(String[] dir) method before loading the presentation instance.
When rendering the presentation in pdf format, it generated a warning callback message given below:

Font substituted from Albany WT J to {SansSerif}.

I am wondering from where Albany WT J come as its not used in the presentation.


If we do not load custom fonts then no such message comes.

It means the ‘X’ font in warning callback need not be the font used in presentation which contradicts the definition of warning callback message provided by you in the above post.

The presentation is attached with this mail.


Thanks
Praneeth




Hi Paraneeth,

I have observed the results shared by you and request you to please working sample code along with presentation file. I also request you to please provide me the list of fonts registered in your OS along with those which you are calling locally using LoadExternalFonts() method. I will discuss that with our development team to help you further in this regard.

Many Thanks,

Hi,


The sample code is given below:

public class PptToPdf
{
public Presentation createPresentation(byte[] inputDoc) {
Validate.notNull(inputDoc, “Could not create a Presentation object with null byte array for doc”);

final InputStream inputStream = new ByteArrayInputStream(inputDoc);

try {
LoadOptions lo = new LoadOptions();
lo.setWarningCallback(new HandleFontsWarnings());

String[] dir = { “/u02/products/fonts” };
FontsLoader.loadExternalFonts(dir);

Presentation ppt = new Presentation(inputStream, lo);
return ppt;
} finally {
StreamUtils.closeQuietly(inputStream);
}
}

public void convertToPdf(byte[] inputDoc, String PdfFileName) {
Validate.notNull(inputDoc, “Could not create a Presentation object with null byte array for doc”);
Presentation ppt = createPresentation(inputDoc);

ppt.save(PdfFileName, SaveFormat.Pdf);

}
}
public class HandleFontsWarnings implements IWarningCallback {

  public int warning(IWarningInfo warning)
{
System.out.println(warning.getDescription()); // “Font will be substituted from X to Y”
return ReturnAction.Continue;
}
}

Please find the attached sample presentation along with the list of fonts available at the target machine.

The fonts available at the external directory are:

LiberationSerif-Regular.ttf
LiberationSerif-BoldItalic.ttf
LiberationMono-Italic.ttf
LiberationSerif-Bold.ttf
LiberationMono-Regular.ttf
LiberationSans-Italic.ttf
LiberationSans-BoldItalic.ttf
LiberationMono-BoldItalic.ttf
LiberationSans-Bold.ttf
LiberationSerif-Italic.ttf
LiberationMono-Bold.ttf
LiberationSans-Regular.ttf
oracle-wingding.ttf
ALBANWTS.ttf
ALBANWTJ.ttf
ALBANWTK.ttf
ALBANWTT.ttf


Please let me know if you need more information.

Thanks
Praneeth







Hi Paraneeth,

Thanks for sharing the information with us. I have created an issue with ID SLIDESJAVA-34742 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 automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

The issues you have found earlier (filed as SLIDESJAVA-34736) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Praneeth,

We have investigated the issue SLIDESJAVA-34736 related to IWarningCallback implementation for font substitution not completely showing the font name. The cause of issue is difference between encoding of strings and console. Java strings encoding is Unicode. For the correct display of the font names you can change console encoding to UTF-8 or save generated warnings to file with UTF-8 encoding.

class HandleFontsWarnings implements IWarningCallback
{
StringBuilder warnings = new StringBuilder();

public int warning(IWarningInfo warning)
{
warnings.append(warning.getDescription() + System.getProperty(“line.separator”));
return ReturnAction.Continue;
}

public void saveWarnings(String fileName)
{
Writer writer = null;
try {
writer = new OutputStreamWriter(new FileOutputStream(fileName), “utf-8”);
writer.write(warnings.toString());
writer.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException ex) {
}
}
}
}
}

public void testWarnings(){
String path = “D:/”;
LoadOptions lo = new LoadOptions();
HandleFontsWarnings handle = new HandleFontsWarnings();
lo.setWarningCallback(handle);
String fileName = “ModifiedKoreanPpt.pptx”;
Presentation pres = new Presentation(path + fileName, lo);

System.out.println(“Converting Ppt to Pdf”);
pres.save(path + “PPTConverted.pdf”, SaveFormat.Pdf);
handle.saveWarnings(path + “out.txt”);
}

Many Thanks,

The issues you have found earlier (filed as SLIDESJAVA-34737) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Praneeth,


Our product team has requested for sharing of ALBANWTJ.ttf for testing as they need this to verify SLIDESJAVA-34742. Please share the requested information so that we may proceed further with our investigation.

Many Thanks,

The issues you have found earlier (filed as SLIDESJAVA-34742) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.