Using External Font(Without Installing on system) in java


#1

I am trying to use external fonts(Without Installing them on system). I am not able to apply that external font on the IAutoShape. Below is my code.

String[] _fontDir = new String[]{"/home/user1/Downloads/metal-macabre"};

// Load the custom font directory fonts.
FontsLoader.loadExternalFonts(_fontDir);

// Do Some work and perform presentation/slides rendering.
Presentation presentation = new Presentation("/home/prdxn70/Downloads/demo2.pptx");

//Get First Slide.
ISlide slide = presentation.getSlides().get_Item(0);

// Adding and accessing Autoshape.
IAutoShape aShp1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 40, 100, 450, 50);
// Accessing the text frame of created autoshape
ITextFrame txtFrm = aShp1.getTextFrame();
// Removing the default exisiting paragraph
txtFrm.getParagraphs().removeAt(0);
// Creating a paragraph 1.
Paragraph para1 = new Paragraph();
// Setting paragraph text
para1.setText(“Create high-value networks.”);
para1.getParagraphFormat().getDefaultPortionFormat().setFontHeight(28);
// Adding Paragraph to text frame.
txtFrm.getParagraphs().add(para1);
txtFrm.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
txtFrm.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(140,149,153));
aShp1.getFillFormat().setFillType(FillType.NoFill);
//Setting no border for shape.
aShp1.getLineFormat().getFillFormat().setFillType(FillType.NoFill);

// Save the presentation.
presentation.save("/home/user1/Downloads/output.pptx", SaveFormat.Pptx);

// Clear Font Cache.
FontsLoader.clearCache();

please help… What I am missing? Why I can’t able to apply the external(Without installing them) font style by default

Thanks.


#2

@saquibs,

Can you please share source file along with generated result so that we may investigate this on our end to help you out.


#3

Source file.:-
dummy.java.zip (933 Bytes)

Output file:-
output2.pptx.zip (14.7 KB)

Font to Apply Without Installation on system:-
metal-macabre.zip (19.7 KB)


#4

@saquibs,

Can you please share source file which you used on your end so that we may further investigate to help you out. The file you share include generated result along with sample code and source fonts.


#5

Whatever I have shared I am using same source. There is no extra source I am using. My sample code is my source code. I just want to apply external font style which is not installed on system.

Thanks.


#6

@saquibs,

Confirm you please confirm about demo.pptx file is your source file. If yes, than please share that file with me.


#7

There is nothing in that pptx. You can share code by just applying external font to pptx file which is not installed on system.

For safe side this is my demo.pptx :-
demo.pptx.zip (17.6 KB)

Thanks.


#8

@saquibs,

Can you please try to use following code snippet on your end and share feedback with us if there is still an issue.

FontsLoader.loadExternalFonts(new String[] {“fonts1”});
Presentation presentation = new Presentation(“outputtestfont.pptx”);

//Get First Slide.
ISlide slide = presentation.getSlides().get_Item(0);

// Adding and accessing Autoshape.
IAutoShape aShp1 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 40, 100, 450, 50);
// Accessing the text frame of created autoshape
ITextFrame txtFrm = aShp1.getTextFrame();
// Removing the default exisiting paragraph
txtFrm.getParagraphs().removeAt(0);
// Creating a paragraph 1.
Paragraph para1 = new Paragraph();
// Setting paragraph text
para1.setText(“Create high-value networks.”);
para1.getParagraphFormat().getDefaultPortionFormat().setFontHeight(28);
// Adding Paragraph to text frame.
txtFrm.getParagraphs().add(para1);
txtFrm.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setLatinFont(new FontData(“Metal Macabre”));
txtFrm.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
txtFrm.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().getSolidFillColor().setColor(new Color(140,149,153));
aShp1.getFillFormat().setFillType(FillType.NoFill);
//Setting no border for shape.
aShp1.getLineFormat().getFillFormat().setFillType(FillType.NoFill);

// Save the presentation.
presentation.save(“outputtestfont1.pptx”, SaveFormat.Pptx);


#9

Issue not solved. You can see in Below Screenshot. External font name is displaying in font style box as “Metal Macabre” but the font style not get changed. font style is still in "Arial"

img2.jpg (123.3 KB)


#10

@saquibs,

I have observed the screen shot provided by you. You are infact opening the generated presentation in a machine which is suppose to have Metal Macabre installed. Can you please ensure if this font is both installed in your source machine and machine where you are opening the presentation. Moreover, can you please also share the details about Metal Macabre font availability on your end.


#11

As I have mention above that font is not installed on system I am using MetalMacabre.ttf file to apply font style External. I want to use this font(Metal Macabre) which is not installed on system. Is it possible to use font style without font installation?

As per this article I am trying to use external font without installation.
https://docs.aspose.com/display/slidesjava/Managing+Fonts#ManagingFonts-UsingCustomFontswithoutInstallingthem


#12

@saquibs,

I have worked with problem you are facing. I have shared project via dropbox. Please check following link.


#13

Good work!! Thanks… But I want to inform that font style has been applied in PNG image. PPTX still has same problem. Font name as Metal Macabre visible but style has not been applied on PPTX. I want to know do MS PowerPoint has same problem? I am using LibreOffice Impress in Ubuntu to view Power Point slide.

Thanks.


#14

@saquibs,

I like to inform that project which i have shared with you successfully applied fonts in Presentation and PNG image as well. Please try to open generated presentation in PP. Also please confirm if you used project which i have shared with you.


#15

Thank you so much. Happy to inform you that your code works. It was error of LibreOffice Impress in ubuntu. It does not allow to load the external font. Well supported in MS PowerPoint.

Thanks.


#16

@saquibs,

You are very welcome.