Could not find any font linex

Hi Team,
My code works properly in Windows machine but when I run it on linex system, it says the fonts are not loaded.

I'm using aspose.pdf 9.5.0 version. I got upgraded from Aspose.Pdf.Kit.

I found a forum link which addressed similar issue but I don't find the suggested code relevant in my case - PDFNEWJAVA-33945 System default font should be used in case of missing fonts

Here is the stack trace.

com.aspose.pdf.internal.p233.z8: Could not find any font. Use Document.addLocalFontPath(String path) to set correct path for your fonts location.
at com.aspose.pdf.internal.p432.z16.m1(Unknown Source)
at com.aspose.pdf.internal.p432.z16.m8(Unknown Source)
at com.aspose.pdf.internal.p432.z16.m7(Unknown Source)
at com.aspose.pdf.internal.p432.z16.m1(Unknown Source)
at com.aspose.pdf.internal.p434.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p432.z29.m9(Unknown Source)
at com.aspose.pdf.internal.p432.z29.m21(Unknown Source)
at com.aspose.pdf.internal.p430.z13.m3(Unknown Source)
at com.aspose.pdf.internal.p430.z7.(Unknown Source)
at com.aspose.pdf.internal.p430.z9.(Unknown Source)
at com.aspose.pdf.internal.p430.z13.(Unknown Source)
at com.aspose.pdf.internal.p429.z8.m1(Unknown Source)
at com.aspose.pdf.internal.p432.z29.m28(Unknown Source)
at com.aspose.pdf.internal.p432.z29.m1(Unknown Source)
at com.aspose.pdf.internal.p432.z31.m1(Unknown Source)
at com.aspose.pdf.internal.p434.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p433.z4.m1(Unknown Source)
at com.aspose.pdf.internal.p434.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p434.z1.m2(Unknown Source)
at com.aspose.pdf.TextBoxField.m2(Unknown Source)
at com.aspose.pdf.WidgetAnnotation.m1(Unknown Source)
at com.aspose.pdf.Field.updateAppearances(Unknown Source)
at com.aspose.pdf.Field.m6(Unknown Source)
at com.aspose.pdf.Field.setValue(Unknown Source)
at com.aspose.pdf.TextBoxField.setValue(Unknown Source)
at com.aspose.pdf.facades.AForm.fillField(Unknown Source)
at com.aspose.pdf.facades.Form.fillField(Unknown Source)

Could you please suggest me something/workaround? Is this a known bug?

Thanks,
Tvk Reddy

Hi Tvk,


Thanks for your inquiry, As suggested in your referenced post, on non-windows OSs issue caused due to font folder path setting. For example, at my machine Ubuntu 13.10 I have installed Microsoft fonts and setting font path as following. You need to set font folder path according to your machine setting.

sudo apt-get install ttf-mscorefonts-installer

// Set font folder path
String path = “/usr/share/fonts/truetype/msttcorefonts/”;
// Adding a single font directory
// com.aspose.pdf.Document.addLocalFontPath(path);

// seting the user list for standard font directories
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
list.add(path);

com.aspose.pdf.Document.setLocalFontPaths(list);



Please feel free to contact us for any further assistance.

Best Regards,

Hi Ahmad,


Thanks for your quick reply. I understand that the path would be different for linux systems, but my concern was more of what method to be used for com.aspose.pdf.facades.Form class.

I’m not using com.aspose.pdf.Document in my code.

My code is like this:

ByteArrayOutputStream bout = new ByteArrayOutputStream(rawData.length);
Form pdfForm = new Form(new ByteArrayInputStream(rawData), bout);
pdfForm.fillField(fieldName, fieldValue);
pdfForm.save();

return bout.toByteArray()


I don’t think the code you mentioned is applicable here. If its applicable then can you please give an example with the above code snippet?

Thanks,
Tvk Reddy

Hi Tvk,


Thanks for your inquiry. Same method will be used for Facades as well. it uses same font settings.

Moreover please note now input and output is dealt separately in Facades package using bindPdf() and save() method, please check following code for reference. Moreover, if you want you can use Document object in bindPdf() constructor as it accepts Document object as well.

// Set font folder path<o:p></o:p>

String path = "/usr/share/fonts/truetype/msttcorefonts/";

// Adding a single font directory

// com.aspose.pdf.Document.addLocalFontPath(path);

// setting the user list for standard font directories

java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();

list.add(path);

com.aspose.pdf.Document.setLocalFontPaths(list);

InputStream is = new ByteArrayInputStream(rawData);

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(is);

ByteArrayOutputStream bout = new ByteArrayOutputStream(rawData.length);

Form pdfForm= new Form();

pdfForm.bindPdf(pdfDocument);

//Form pdfForm = new Form(new ByteArrayInputStream(rawData), bout);

pdfForm.fillField(fieldName, fieldValue);

pdfForm.save(bout);

return bout.toByteArray()


Please feel free to contact us for any further assistance.


Best Regards,

Hi Ahmed,


This works!! Many Thanks for your help :slight_smile:

Tvk

Hi Tvk,


Thanks for your feedback. It is good to know that code snippet worked for your to accomplish the task.

Please keep using Aspose API and feel free to asks any question or concern. We will be glad to extend our support.

Best Regards,

Hi Ahmed,


Using the code snippets provided by you we have run into another problem. The form.fillField method does add the values to the fields but when the value size is too large it gets reduced to such small font which is unreadable. Even if we try to zoom in the whole pdf expands but the value does not.

For example when the value is “Raj” it works absolutely fine. If we change the value to “qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq” a straight line is shown. It seems the length of the output to be displayed remains the same irrespective of the length of the value. Thus whether the value is “A” or “Raj” or “qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq” it tries to squeeze the display in the same length.

Could you help here as to what can be done to adjust the font for the values to be updated in the PDFs.

Regards,
TVK

Hi TVK,

Thanks for your inquiry. While testing the scenario with latest version of Aspose.Pdf for Java 9.7.0, we have managed to notice the font size issue and logged an investigation ticket PDFNEWJAVA-34632 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,