We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Embed an External Font with .pptx file

Hello Aspose Team,
I have a written a code in java to embed fonts with .pptx fil.
Here is mine step -->
1.First of all i get path of “ttf” file from my local directory.
Path path = Paths.get(dir+“customFont.ttf”);

2.Then i convert it into byteArray.
byte[] fileContent = Files.readAllBytes(path);

3.Then i load this byteArray object.
FontsLoader.loadExternalFont(fileContent);

  1. Finally i embed this byteArray object i.e. Fonts byteArray Data with new presentation.
    presentation = new Presentation();
    IFontsManager manager = presentation.getFontsManager();
    System.out.println(manager.getEmbeddedFonts().length+"\n");
    manager.addEmbeddedFont(fileContent, 1);

ISSUE -->
1. my custom font is embedded with .pptx file but when i’m opening this .pptx file into microsoft powerpoint, i’m getting an error like a dialog box, in which “SOME OF EMBEDDED FONTS IN YOUR PRESENTATION CAN NOT BE INSTALLED; REASONS --> GENERAL FAILURE” is written.
Why this issue is occurred. anyone can help me.Plz

THANKS! In advance.
NOTE—> i’m using latest library 18.8…

If any person have own idea(codes) then please share with me.
I’m the new person in Aspose.slide library.

@AbhiG,

I have observed your requirement and like to share that you can please visit this documentation link to see how to embed fonts inside presentation. In your sample code you are not embedding font in presentation any where.

Hi @Adnan.Ahmad
Just have a look on following few lines of code,If i am not a wrong then this will embedded the font inside the .pptx.

  1. presentation = new Presentation();
    IFontsManager manager = presentation.getFontsManager();
    manager.addEmbeddedFont(fileContent, 1);

In highlighted line “fileContent” variable will have the font file which i want to embedded & the value 1 will represent same EmbedFontCharacters.All can you please guide where exactly i am going wrong.

Hi @Adnan.Ahmad
The document, you are referred in which coding is written for embed font i.e. already embed fonts(i’m not sure) but i want a font embed during creation of .pptx file. So
Now i’m explaining what i need
I’m creating a .pptx file from coding in which also write Some Texts.
And applying FontsFamily i.e. loaded from local directory(i.e not installed in system).
And this loaded fonts i embed with .pptx file and fonts also embed with .pptx file.
But my issue is that when i open .pptx file into MS power point 2007,13,16, then
i get a dialog box in which error message like " SOME OF EMBEDDED FONTS IN YOUR PRESENTATION CAN NOT BE INSTALLED; REASONS --> GENERAL FAILURE" is written.
What is wrong with my code that i given in above.

@AbhiG,

I have observed your issue and request you to please provide the source presentation, source font used, generated presentation and snapshot of issue. We will be able to investigate issue further on provision of requested information.

@Adnan.Ahmad
I have used code that you referred document.
Here is coding —>
Presentation pres=new Presentation("/home/abhiG/Desktop/Pres.pptx");
IFontData[] allFonts = pres.getFontsManager().getFonts();
IFontData[] embeddedFonts = pres.getFontsManager().getEmbeddedFonts();
for (IFontData font : except(allFonts, embeddedFonts))
{
pres.getFontsManager().addEmbeddedFont(font,EmbedFontCharacters.All);
}
try{
pres.save("/home/abhiG/Desktop/Pres.pptx",SaveFormat.Pptx);
}catch(Exception e){
e.printStackTrace();
}

But,I’m getting an error like
"
Exception in thread “main” java.lang.UnsupportedOperationException: Not supported yet.
"
And i think this is exception that is throws by your method i.e
"
private static Iterable except(IFontData[] allFonts, IFontData[] embeddedFonts) {
throw new UnsupportedOperationException(“Not supported yet.”); //To change body of generated methods, choose Tools | Templates.
}
"
Can you explain about it. why this error is occurred.
Please explain in deeply,
Thank in advance @Adnan.Ahmad,@mudassir

@AbhiG,

I have observed the issue shared. Can you please provide the source presentation, used fonts, Java and Operating system detail on your end. We will investigate the issue on our end based on shared information.

@Adnan.Ahmad
This is my .pptx file
abhiG.pptx.zip (104.5 KB)
And you have also seen my code above.
And Exception which occurred is written by your method.
And i have picked your source code so can you explain when and why this exception occurs.

@AbhiG,

I have tried using your following code on my end and unable to find definition of Except method. In-fact, compile error is thrown for this. Secondly, you have also not shared those fonts that you are trying to embed in your presentation. From your code logic it seems as if you are trying to embed all fonts used in presentation. Can you please share a working example.

public static void TestEmbeddedFont()
{
     String path="D:\\Aspose Data\\abhiG\\";
     Presentation pres=new Presentation(path+"Pres.pptx");
     IFontData[] allFonts = pres.getFontsManager().getFonts();
     IFontData[] embeddedFonts = pres.getFontsManager().getEmbeddedFonts();
     for (IFontData font : except(allFonts, embeddedFonts))
     {
        pres.getFontsManager().addEmbeddedFont(font,EmbedFontCharacters.All);
     }
    try
    {
        pres.save(path+"Pres2.pptx",SaveFormat.Pptx);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}
private static Iterable except(IFontData[] allFonts, IFontData[] embeddedFonts)
{
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

}

@Adnan.Ahmad
Thanks for your kindness your code is working.

@AbhiG,

It is good to know things have worked on your end.