Where do I install fonts under Mac OS X and Unix?

Hi,



I am using Aspose.Slides for Java 2.7.0. My particular use case is taking PPT files generated in PowerPoint on Windows, doing some text replacements, and then producing PDF output.



At the moment, default fonts are being used in the PDF output, because the original fonts are not available to Aspose.Slides. I have all of the original fonts required, I just don’t know where to put them. I need to know where to put them under Mac OS X (Lion) for development, and Linux (CentOS) for deployment. Where does Aspose.Slides look for fonts during PDF output on these two platforms?



Apologies if this is a FAQ—surely it must be. I’ve searched the Knowledge Base, FAQ, forums and wider with Google, but I’m coming up blank. Thanks.

Hi Paul,


Thanks for your interest in Aspose.Slides.

Aspose.Slides looks for fonts in the default font place where Linux or Mac OS install them. Please also visit this thread link for your further kind reference.

Many Thanks,

Thanks Mudassir. I had tried installing additional fonts in ~/Library/Fonts under OS X, and it wasn’t clear whether they were being picked up by Aspose. I will carry on.

It would certainly make deployment easier if I could bundle the required fonts with the application, perhaps in a JAR. Does Aspose.Slides support loading font resources from a JAR like this, or, if not directly, can anyone suggest the appropriate Java (1.6) idiom to get fonts from a JAR so that they are visible to Java, and hence Aspose?



(I assume what I need to know is how Aspose.Slides obtains the fonts it needs from Java. I can find quite a bit of information on making fonts available to Swing, for example, via java.awt.Font.createFont(). What I can’t work out is how this hooks into the Aspose.Slides API. Say I have a TTF file for a font used in a PPT presentation. Say I can’t install that in the usual place for the OS in question. How can I make it available to Aspose.Slides via, say, an InputStream?)

Hi Paul,


I have requested our development team about the status of the issue. An issue with ID SLIDESJAVA-33134 has been created as investigation in our issue tracking system. I will share the response with you as soon as it is shared by our development team. But, my initial response to your query is that it is not possible via Aspose.Slides for Java they way you have shared your query related to fonts management.

Many Thanks,

Thanks Mudassir. I look forward to hearing if the development team can offer any additional advice.

Hi Mudassir,



I’ve put some further work into this, and I can be more specific about what I need to know. Perhaps you could update your internal issue tracker with this additional information?



1. I have a situation where I can’t install some required fonts at the OS level, but I can ship them with the application.



2. I need to get PNG and PDF output from a Presentation.



3. I can get PNG output with the correct font. It appears to be sufficient just to call Font.createFont() with an InputStream pointing to a specific font prior to calling ImageIO.write() with the BufferedImage supplied by Slide.getThumbnail(). I don’t even need to call GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont() to make this work.



4. No matter what I try, I cannot get Presentation.save() to use the correct font in a save to PDF. I have tried:



* Calling Font.createFont() as above, which works for rendering to PNG.

* Calling GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont() with the font in question.

* Setting setEmbedTrueTypeFontsForASCII(true) and setEmbedTrueTypeFontsForASCIIChars(true) on the PdfOptions object that I supply to the save() method.



What I need to know is what is the significant difference in how Slide.getThumbnail() and Presentation.save() obtains a font from the Java environment? How can I supply a font for saving as a PDF at runtime?

Hi Paul,

Thanks for sharing your further views. I have observed that you are able to render the thumbnails in correct font. However, the issue happens on your side while exporting to PDF. Please share the source presentation, generated thumbnails and PDF with us so that I may add that in our issue tracking system as a separate issue. Please share the code snippet that you are using on your end along with Aspose.Slides for Java version that you are using. Please also share the complete environment details as well.

Many Thanks,

Thanks Mudassir. I will put together a minimal example that demonstrates the difference between PNG and PDF output. It will take me a day or so.

Here is a minimal example. This should be completely self-contained. README at the top level explains how to reproduce.

Hi Paul,


I have installed the font shared by you and have worked with your presentation in Windows 7 environment and have been able to generate the correct PDF and thumbnail using Aspose.Slides for Java 2.8.0. However, I still need to verify the same in Mac OS and need some time for setting up the environment. For your kind reference, I have shared the generated PDF and thumbnail. I will share the information related to Mac OS ASAP. Please download Aspose.Slides for Java in the shared link attached Jar files.

Many Thanks,

Hi Mudassir,



Thanks for your work on this. I note that you say that you “installed the font”. This is very important—I am trying to obtain a solution here that does not involve “installing” the font. (Indeed, I can generate a PDF with the correct font if I install the font in the usual place for the relevant OS. That’s not the issue.)



Were you able to run the code I supplied? You need to make sure the font I supplied is not “installed” anywhere—the code sample picks up the font at runtime before it generates the PNG and PDF. This is critical.



My use case is for supplying fonts as part of an application bundle, along with Aspose.Slides. I really need a solution that doesn’t involve “installing” those fonts ahead of time. (The title of this thread is now obsolete!)



Thanks again for looking into it. Please try running the code again without installing the font I supplied.

Hi Paul,

I got your requirements. I am afraid it would not be possible to use the font that is in fact not installed. However, I have updated the issue status and our development team will further investigate this issue. I will share the further information with you as soon as it is shared.

Many Thanks,

Hi Mudassir,



Thanks a lot for sticking with this, and your prompt replies. I really appreciate it.



The issue is that I’ve demonstrated that I can produce a PNG without having a font “installed” in the OS. The code I’ve supplied demonstrates that. All I need to do is load the font at runtime from somewhere, and construct a Font object with it. The PNG production process then finds that font. It doesn’t need to be installed in any OS-specific way.



What I would love to know from the development team is the significant difference between PNG thumbnail production and PDF production that means I can’t load a font at runtime for PDF production. Is there some other Graphics2D/ImageIO/AWT method I can call to expose the runtime font to the PDF rendering process?



Again, thanks for sticking with me on this. I hope the development team can provide some insight.

Hi Paul,


I have shared the observation with our development team. Our development team will further investigate the issue and we will share the response with you as soon as it is shared.

Many Thanks,

Hi Mudassir,



Since my earlier posts in this thread, my initial success with producing PNGs by loading fonts at runtime (which I demonstrated in the code sample attached) has been tempered by some failures. Some fonts will appear in the PNG output using this method, and some won’t—I haven’t been able to determine the pattern, either.



So, to summarise, this is my use case:



1. I intend to deploy Aspose.Slides as part of a web application.

2. I may not be in a position to “install” required fonts at the OS level. In any case, distributing them with the application in JAR format is certainly much more convenient.

3. I want to be able to produce PNG and PDF output from Presentations that I create from existing PPT files that are part of the application. I have all of the fonts required, and can distribute them with the application.



As noted, I have had limited success (using methods from Java’s Font and GraphicsEnvironment classes) as described in previous posts, and as demonstrated in my sample code. What would be great to know from your development team is whether there are:



1. Any other plain Java mechanisms for getting these fonts exposed to Aspose.Slides at runtime? If GraphicsEnvironment.registerFont() is not sufficient, is there some other way?

2. Are there any hooks in Aspose.Slides that I have missed for loading fonts at runtime? I notice that in Aspose.Pdf for Java, for example, there is the Pdf.setTruetypeFontDirectoryPath() method for indicating the path to fonts at runtime. Is there anything similar in Aspose.Slides?

3. Are there any plans to add a feature for runtime loading of fonts for Aspose.Slides in the future?



Thanks for any further help you can provide.

Hi Paul,


The issue shared by you is already under investigation. I have shared the information shared by you with concerned developer. As soon as some information will be available, I will be more than happy to pass on that to you.

Many Thanks,

Hi Paul,


I like to share that in Aspose.Slides for Java 2.8.1, we have shared the approach for loading the custom fonts from desired location. Please use the approaches shared below for loading the custom fonts in your presentation.

import com.aspose.slides.FontsLoader;
//load external fonts method passes array with paths to folders with custom fonts
FontsLoader.loadExternalFonts(new String[] { /windows/ “D:/fonts” , /unix/ “/home/user/fonts” });
Presentation p = new Presentation(…);


Optionally you can add custom fonts directories to Java-machine command line parameters, for example:

java … -Daspose.custom.fonts=D:/fonts1;D:/fonts2;D:/fonts3 …

in this case you should also invoke font loader berfore any presentations creation:

import com.aspose.slides.FontsLoader;

FontsLoader.loadExternalFonts(null);

Presentation p = new Presentation(…);

The solutions work only for java 1.6 and higher

Please share, if I may help you further in this regard.

Many Thanks,

Thanks Mudassir. I’ll be back on this project next week, and will have a look at it then.

Hi Mudassir,



I note that the Aspose.Slides for Java 2.8.1 download to which you have linked does not seem to contain the latest Javadoc API. In particular, the new FontsLoader class is not present. Is it possible to get a look at the Javadoc API for 2.8.1? (It also doesn’t seem to be accessible online here, though I may be mistaken.) If you can point me to any copy of it, that would be great.