PDF generated with aspose doesnot apply Font and FontStyle in Unix server

Hi,

I am working on a code where we are generating pdf document with Aspose and have some texts BOLD, ITALIC and UNDERLINED, which works fine when I generate the document from my local Windows machine. But when I deploy the same to unix Dev box in the generated document the FontStyles are missing. All text are plain, no BOLD, No Italic and no underlined.

Thanks,
Prashant

@prashant.ghoderao

Thanks for contacting support.

We have tested the scenario in UNIX environment with Aspose.PDF for Java 17.12 (i.e latest version of the API) and were unable to replicate the issue which you have mentioned. For your reference, we have attached sample code snippet and a generated output as well.

Document doc = new Document();
Page page = doc.getPages().add();
TextFragment tf = new TextFragment("This is bold text");
tf.getTextState().setFontStyle(FontStyle.TimesBold);
TextFragment tf2 = new TextFragment("This is italic text");
tf2.getTextState().setFontStyle(FontStyle.TimesItalic);
page.getParagraphs().add(tf);
page.getParagraphs().add(tf2);
doc.save(dataDir + "BoldItalic.pdf");

BoldItalic.pdf (2.3 KB)

Would you please share your environment details (i.e JDK Version) along with sample code snippet which you are using at your side - so that we can test the scenario again in our environment and address it accordingly.

Thanks Asad for your reply.
We are currently using Aspose 16.12.0 version and JDK version is 1.7.
here is the code snippet we are using for making FONT BOLD, ITALIC and UNDERLINE.

if(isBold && isItalic){
text.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold | com.aspose.pdf.FontStyles.Italic);
} else if(isBold){
text.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
}else if(isItalic){
text.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);
}

Hi Asad and team, Could you please expedite the same which prashant have raised. We have a production release and this will create a issue if it is not fixed. We have got the license as well so please help us…

@KumarAnnamalai, @prashant.ghoderao

Thanks for writing back.

We have tested the scenario again with your code snippet while using latest version of the API and were unable to replicate the issue in our environment. Please note that it is always recommended to use latest version of the API, because it contains more fixes and enhancements. Also, the issues logged for old version(s) of the API are used to be resolved in latest version.

Furthermore, please make sure that all necessary fonts, which are being used in PDF, are completely installed in your environment because sometimes issue(s) may occur due to incomplete font package(s). Also, please try using latest version of the API and in case you still face any issue, please share a sample application which is able to replicate the issue, so that we can test the scenario in our environment and address it accordingly.

PS: For your reference, we have also attached an output PDF document, generated while testing the scenario. BoldItalic.pdf (1.9 KB)

@asad.ali
Hi Asad, Sure we will share the details.
Mean while can you please let us know what is your environment. What OS(Unix / Windows) you are using and what is the version(Release) of the OS. What are all the font packages installed in the machine. Can you please throw as much light as possible on the environment details.
As a next step we can move to the latest version of API but we need to figure out the root cause before confirming it is an issue with lower version of API since it could be an environmental issue as well since the version of API we used is working in the laptop which is a windows machine.
So once you share the environment(OS) details we will verify and even if it is not working we shall move to the latest Aspose version.
Thanks
@KumarAnnamalai

@KumarAnnamalai

Thanks for getting back to us.

We have tested the scenario in an environment i.e Linux CentOS 7 x64 and Ubuntu 15.04 x64 (Clone of UNIX OS), Eclipse, Console Application, JDK v1.8 and we have used the code snippet(s), which has been shared in this forum thread already. Concerning to the fonts, we have generated PDF document with default fonts (e.g we did not specify any font for TextFragments while generating the PDF). So in case you are specifying any specific font while generating the PDF which is not installed in the system, the issue may occur.

Some fonts are used to be installed along with their bold and italic packages separately (e.g FontName Bold, FontName Italic). Furthermore, Windows operating systems use to support maximum fonts by default as compared to Linux/UNIX based operating systems do. Which was why we suggested you to install necessary fonts in your environment and try again.

It seems more of environment specific issue, however using latest version of the API may resolve this issue as such issues are mostly handled in latest version of the API. You can try latest version in a small sample application, in order to test how it goes and if you still face any issue, please share same application with us along with generated PDF document. We will again test the scenario with your application and log an investigation ticket, if necessary.

@asad.ali
Hi Asad, As per your recommendations we have used the latest API and it didnt worked and also we tried using the latest API with the code you have shared that also didn’t work. Please can you create a ticket for us and also share the contact details so we can have a call with the environment team

@KumarAnnamalai

Thanks for writing back.

Please note that we provide support through forums and will really appreciate if you can please share your environment details with us in here. Also, as shared earlier, please share a sample application, which produces the issue in your environment so that an investigation ticket can be generated with all necessary information.

@asad.ali
Hi Asad, Appreciate your help. We are able to see the bold and Italics if we are not loading the font(Open Font). Is there a way to have the openfonts work by referencing the TTF file in our configuration folder even though fonts are not installed on the server ?
Please let us also know if there are any other work around since we tried both new Aspose version and the version we used 16.12.0 ? Please help we have to fix this issue to go live in production next week and get user sign off this week.

@KumarAnnamalai

Thanks for contacting support.

In order to specify/load TTF fonts from a specific resource folder, please use following code snippet:

Document pdf1 = new Document();
Page p1 = pdf1.getPages().add();
TextFragment text1 = new TextFragment("Sample String...");
com.aspose.pdf.Font f = FontRepository.openFont("C:\\Softwares\\Aspose\\Fonts\\18875_HelveticaCdBd.ttf");
f.setEmbedded(true);
text1.getTextState().setFont(f);
p1.getParagraphs().add(text1);
pdf1.save(myDir+"Output.pdf"); 

In case of any further assistance, please feel free to contact us.

@asad.ali: Thanks for sharing the code but unfortunately it didn’t work. Please let us know why italic/bold is working on server when we dont set the font. The style only works when we dont setFontStyle.
Please help we are struck. FYI, we have got the enterprise SITE OEM pricing plan but still it is painful that we couldn’t get support and we have to wait for hours to get the reply from this open forum.
Please let us know whether we can arrange for a call with the Unix team to speed up things and we can show our code as well. We have production live next week.

@KumarAnnamalai

Thanks for contacting support.

Please note that in non Windows environments, this type of issue mostly occur due to font loading problems. However, these issues can be overcome by specifying path to resource folder, which code snippet have been shared in my previous reply. Please also check following code snippet, in order to set font directory for PDF document, while generating them:

String path = "path/to/my/folder";
List fontPaths = com.aspose.pdf.Document.getLocalFontPaths();
fontPaths.add(path);
com.aspose.pdf.Document.setLocalFontPaths(fontPaths);

We apologize for keeping you wait. However, please note that in Free/Normal Support Forums, we always try to respond our customers as soon as possible - and only reason of getting a delayed response could be difference between the time zones.

As shared earlier, we do not provide support over call or email but only through our forums. Also, in order to investigate/fix the issue, we need to observe same issue in our environment, which we could not manage to do. Which was why we requested you to share your environment details (i.e UNIX Version, Application Type, etc.) along with complete code snippet. This would really help us in trying to replicate the issue in our environment and address it accordingly.

PS: You may also share requested details in a private message. You may send a private message by clicking on username and using “Message” Option.