Is it possible to add custom font to PDF document?

Hi,


We have our custom .ttf font in our Android application assets.

Does Aspose library support adding (embedding) that font to a PDF document? If yes, please point to a corresponding API.

We are going to add free text annotations which use the font.

Thanks!
Vit Khudenko

Hi Vit,

Thanks for your inquiry. You may use DefaultAppearance object to set custom font for a annotation. Please check following code snippet for the purpose. Hopefully it will help you to accomplish the task.

// create an instance of font object and try loading ComicSansMS font from system font repository
com.aspose.pdf.Font font = com.aspose.pdf.FontRepository. findFont("ComicSansMS");

DefaultAppearance default_appearance = new DefaultAppearance( font, 12, java.awt.Color.BLACK );

// Create Free Text annotation
com.aspose.pdf.FreeTextAnnotation textAnnotation =  new com.aspose.pdf.FreeTextAnnotation(document.getPages().get_Item(1),
new com.aspose.pdf.Rectangle(100, 100, 300, 300),default_appearance);

Best Regards,

Hi Tilal,


Thank you for your reply!

I used FontRepository.openFont(“path_to_file”) and it works - I got the Font instance. However I am not able to instantiate FreeTextAnnotation, though this is a different issue. Please take a look: Unalbe to create FreeTextAnnotation

Thanks,
Vit Khudenko

Hi Vit,


Thanks for your feedback. It is good to know that you have manged to accomplish your task.
However we are looking into FreeTextAnnotation issue and will update you in your related thread soon.

Best Regards,

Hi Vit,


Thanks for your patience. Please check your Aspose.Pdf for Android 1.6.0 release. Please download it, it will resolve the issue.

Best Regards,