From reading through various posts I think I know the answer to this however I just want clarification.
I am trying to use the Tahoma font when generating a PDF, however I’d preferably like to be able to just provide a path to the file which is kept within a resources folder for my application e.g. /resources/Tahoma.ttf. Is this possible?
I’ve also tried installing the font into my system -> Fonts and then doing:
final Section sec1 = pdf1.getSections().add();
sec1.getTextInfo().setFontName("Tahoma");
but this causes an error: Font 'Tahoma' not found. Please make sure the customer font file is correctly set.
Any ideas? I can use the core Aspose fonts fine, so I am making do with Helvtica for now, but I could really do with being able to use Tahoma!
Thanks for your inquiry. We are looking into your query and will get back to you soon. Meanwhile, can you please share some details about your working environment and Aspose.Pdf API version. It would help us to test your scenario.
I have tested the scenario and I am able to notice the same problem. For the sake of correction, I have logged this problem as PDFNEWJAVA-34127 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us a little time. We are sorry for this inconvenience.
Thanks for sharing the code snippet. Yes you are correct. The following code can be used with Aspose.Pdf for Java to use a custom font file (even if it’s not installed over the system).
//create the font from a TTF file
com.aspose.pdf.Font myFont = new com.aspose.pdf.FontRepository().openFont("E:\\Package\\fonts\\3OF9_NEW.TTF");
myFont.setEmbedded(true);
//new doc, add a new blank page
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
com.aspose.pdf.Page page = doc.getPages().add();
//use the font in a style
com.aspose.pdf.TextState style = new com.aspose.pdf.TextState();
style.setFont(myFont);
style.setFontSize(12);
style.setFontStyle(com.aspose.pdf.FontStyles.Regular);
style.setLineSpacing(4);
com.aspose.pdf.TextFragment frag = new com.aspose.pdf.TextFragment("This is sample string");
frag.getTextState().applyChangesFrom(style);
frag.setInLineParagraph(true);
page.getParagraphs().add(frag);
//save it
doc.save("C:\\pdftest\\CustomerFont_output.pdf");
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.