We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Incorrect Page count returning in linux but returning correct in windows

Incorrect Page count returning in linux but returning correct in windows

Please see the below code , the code returns correct page count in windows but it is returning the wrong value in linux. (considering each paragraph as a page.)

Output in windows: 1
Output in Linux: 3

import com.aspose.words.BreakType;
import com.aspose.words.ConvertUtil;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.PageSetup;
import com.aspose.words.PageVerticalAlignment;
import com.aspose.words.Section;
public class Test6 {

public static void main(String[] args) throws Exception {
				
		Document document = new Document();
		document.getSections().get(0).getPageSetup().setOrientation(com.aspose.words.Orientation.PORTRAIT);
		
		PageSetup firstpageSetup = document.getFirstSection().getPageSetup();
		firstpageSetup.setPageHeight(ConvertUtil.millimeterToPoint(300.0));
		firstpageSetup.setPageWidth(ConvertUtil.millimeterToPoint(200.0));
		firstpageSetup.setVerticalAlignment(PageVerticalAlignment.TOP);
		
		for (Section sections : document.getSections()) 
		{
			sections.getPageSetup().setTopMargin(ConvertUtil.millimeterToPoint(0));
			sections.getPageSetup().setBottomMargin(ConvertUtil.millimeterToPoint(0));
			sections.getPageSetup().setRightMargin(ConvertUtil.millimeterToPoint(6));
			sections.getPageSetup().setLeftMargin(ConvertUtil.millimeterToPoint(6));
		}
		
		DocumentBuilder db = new DocumentBuilder(document);
		db.insertHtml("Description", true);
		db.insertBreak(BreakType.PARAGRAPH_BREAK);
		db.insertHtml("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna ac ipsum sodales facilisis ut ut elit. Sed tempus aliquam turpis, at consequat tortor pretium tempus. Cras finibus euismod ipsum, eu consequat justo aliquam ultrices. Nullam interdum ligula at massa aliquet convallis. Ut ut mi nunc. Nam semper interdum dictum. Aliquam erat volutpat. Mauris bibendum congue tortor, sit amet volutpat arcu accumsan in. Integer et odio ac urna condimentum feugiat sit amet eget massa. Integer suscipit blandit odio, vitae pellentesque eros mollis eu.</p>",true);			
		db.insertBreak(BreakType.PARAGRAPH_BREAK);
		db.insertHtml("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna ac ipsum sodales facilisis ut ut elit. Sed tempus aliquam turpis, at consequat tortor pretium tempus. Cras finibus euismod ipsum, eu consequat justo aliquam ultrices. Nullam interdum ligula at massa aliquet convallis. Ut ut mi nunc. Nam semper interdum dictum. Aliquam erat volutpat. Mauris bibendum congue tortor, sit amet volutpat arcu accumsan in. Integer et odio ac urna condimentum feugiat sit amet eget massa. Integer suscipit blandit odio, vitae pellentesque eros mollis eu.</p>",true);			
		db.insertBreak(BreakType.PARAGRAPH_BREAK);
		db.insertHtml("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis magna ac ipsum sodales facilisis ut ut elit. Sed tempus aliquam turpis, at consequat tortor pretium tempus. Cras finibus euismod ipsum, eu consequat justo aliquam ultrices. Nullam interdum ligula at massa aliquet convallis. Ut ut mi nunc. Nam semper interdum dictum. Aliquam erat volutpat. Mauris bibendum congue tortor, sit amet volutpat arcu accumsan in. Integer et odio ac urna condimentum feugiat sit amet eget massa. Integer suscipit blandit odio, vitae pellentesque eros mollis eu.</p>",true);			
		db.insertBreak(BreakType.PARAGRAPH_BREAK);
                    document.updateWordCount();
		document.updateFields();
		document.updatePageLayout();

		System.out.println(" Total no. of pages :  "+ document.getPageCount() );
}

}

@harivarma,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for Java 18.6 at Linux operating system and have not found the shared issue. Please use Aspose.Words for Java 18.6.