Font not found on Unix with 9.7.1

Hi everybody.


I use aspose pdf for Java release 9.7.1. I worked on generating some reports from our application to PDF. I use “Arial Unicode MS” font, it works correctly on my local environemnt on Windows, I have installed it there. On unix I set path to TruTypeFontFile with the font. It used to work with version 3.3.0 correctly. Now with the same font file it doesn’t work. I checked that on windows it also crashes if I uninstall font from system (even ifpath to font file is set correctly). As I understand aspose reads font from system anyway. Therefore I installed font on unix too. I did it with fc utility. Although now unix can see font “Arial Unicode MS” it still throws exception. I’ve also tried to add fonts directly in JRE. It has been done but without effect. Below is piece of stack trace:

Caused by: java.lang.IllegalStateException: Font ‘Arial Unicode MS’ not found. Please make sure the customer font file is correctly set.
at aspose.pdf.internal.z152.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.pdftext.FontManager.m3(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.pdftext.FontManager.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.internal.z168.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.internal.z168.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.internal.z221.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.internal.z243.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.internal.z232.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.xml.DocumentBase.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.internal.z206.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.Pdf.m1(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]
at aspose.pdf.Pdf.save(Unknown Source) ~[aspose-pdf-9.7.1-jdk16.jar:9.7.1]

Piece of code which is reponsible for creating pdf:

public Pdf createPDF() {
            Pdf pdf = new Pdf();
	   pdf.setDefaultFontName(“Arial Unicode MS”);

Section section = pdf.getSections().add();
TextInfo headlineTextInfo = new TextInfo();
headlineTextInfo.setFontSize(15);
headlineTextInfo.setFontName(“Arial Unicode MS”);
            headlineTextInfo.setTruetypeFontFileName(pathToTTF);

String example= “test”;
Text text = new Text(subject, headlineTextInfo);

section.getParagraphs().add(text);

	return pdf;
            }
Thank You in advance



Hi there,


Thanks for your inquiry. Please note old generator aspose.pdf is depreciated, it is recommended to use new generator (com.aspose.pdf). In non Windows OSs, If you want to use font name using FindFont() then you need to add font folder path as Document.addLocalFontPath(fontDir). However if you want to user complete font file name then you can use OpenFont() method. Please check sample code as following, it will help you to accomplish the task.

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

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

// Adding a font directory

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

// Added document

Document doc = new com.aspose.pdf.Document();

// default font

TextState textState = new TextState();

textState.setFont(FontRepository.findFont("Times-Roman"));

doc.getPageInfo().setDefaultTextState(textState);

PageInfo pageInfo = doc.getPageInfo();

MarginInfo marginInfo = pageInfo.getMargin();

marginInfo.setLeft(10);

marginInfo.setRight(10);

marginInfo.setTop(30);

marginInfo.setBottom(30);

com.aspose.pdf.Table table = new com.aspose.pdf.Table();

table.setColumnWidths("50 100");

// added page.

Page curPage = doc.getPages().add();

//Font font =FontRepository.openFont("C:\\Users\\ubpaul\\Downloads\\KERALITE.TTF");

for(int i=1;i<=20000;i++){

com.aspose.pdf.Row row = table.getRows().add();

row.setFixedRowHeight(15);

for(int ii=0;ii<8;ii++){

com.aspose.pdf.Cell cell1 = row.getCells().add();

com.aspose.pdf.TextFragment textFragment = new com.aspose.pdf.TextFragment("Content 1 ");

cell1.getParagraphs().add(textFragment);

}

}

Paragraphs paragraphs = curPage.getParagraphs();

paragraphs.add(table);

doc.save("textInUnix.pdf");


Please feel free to contact us for any further assistance.

Best Regards,