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

Free Support Forum - aspose.com

Custom Fonts from ASPOSE word to ASPOSE PDF

Hi ,

We are using both ASPOSE word and PDF. We installed a custom font in one of our local machines and created a word document with that custom font.
When we are calling the service to convert this word to pdf using ASPOSE which was deployed in another machine (which does not have the custom font) ,

We are getting the final pdf with text not in the custom font.

Is there a way we can get the pdf with custom font.

Thanks,
Nagendra.

@nyanamadala900014,

The font must be installed on the machine where you are actually performing Word to PDF conversion. Please refer to the following article:
https://docs.aspose.com/words/net/manipulating-and-substitution-truetype-fonts

You can also try embedding the font inside the Word document and then pass it to service for conversion.

it will be helpfull if you provide the code snippet that embedds the fonts in the word document itself.

@nyanamadala900014,

Please try the following code:

Document doc = new Document("E:\\temp\\19.3.docx");

doc.FontInfos.EmbedTrueTypeFonts = true;
doc.FontInfos.EmbedSystemFonts = true;

doc.Save("E:\\Temp\\19.3.docx");

Hi we are using the below code to add the custom fonts

    FontSourceBase[] fontSources = FontSettings.getDefaultInstance().getFontsSources();
    
    FolderFontSource customFonts = new FolderFontSource( "/usr/local/share/customFonts", true );
    
    List<FontSourceBase> newFontSources = new ArrayList<>();
    
    if(fontSources != null){
        for(FontSourceBase src : fontSources){
        	newFontSources.add(src);
        }
    }
    
    newFontSources.add(customFonts);
    
    FontSettings.getDefaultInstance().setFontsSources( newFontSources.toArray( new FontSourceBase[newFontSources.size()] ));

with the above code we are able to see the custom fonts applied to the pdf, but default fonts are not applying.

final output could be like
image.png (12.8 KB)

but its rendering as
image.png (12.4 KB)

can you please help on this.

Hi @awais.hafeez,

Thanks for the response, if we set the EmbedTrueTypeFonts and EmbedSystemFonts as true, do we need to install the custom fonts where we actually performing Word to PDF conversion

@nyanamadala900014,

In that case, as the fonts are already embedded inside Word document, you do not need to install them on the other machine where you are performing Word to PDF conversion. Hope, this helps.