javaunixms-wordasposeaspose.words

I am using aspose-words library in java to read word document and to report page number. It is working fine in windows but not in UNIX how can i fix?


I am using LayoutCollector in aspose-words library to get the page number of a node.

Document document=new Document(filePath);
LayoutCollector layoutCollector=new LayoutCollector(doc);
NodeCollection paragraphNodes=document.getChildNodes(NodeType.Paragraph,true);
for(Node node:paragraphNodes)
{
 if(node.getType==NodeType.PARAGRAPH){
 int pageNumber=layoutCollector.getStartPageIndex(node);
System.out.println(pageNumber);
}

While i am getting the exact page number in my local windows system but not in UNIX server. it is wrongly reporting the page numbers. Any reason for such behaviour, How can i fix this issue?


Solution

  • The problem in Unix environment might occur because the fonts used in the source document are not available in the environment where the document is processed. To calculate page number of the node Aspose.Words need to build document layout. Upon building document layout, if Aspose.Words cannot find the fonts used in the document the fonts are substituted. This might lead into the layout difference, since substitution fonts might have different font metrics. In turn, this might lead to incorrect page numbers detection by LayoutCollector. You can implement IWarningCallback to get a notification when font substitution is performed.

    The following articles can be useful for you:

    https://docs.aspose.com/words/java/specify-truetype-fonts-location/

    https://docs.aspose.com/words/java/install-truetype-fonts-on-linux/