Hi,
I prepare a document object and then call the getPages().size() ,I do not get the actual number of pages in the document.
To generate a page stamp ,I need the correct total number of pages. I do not have an option of saving the document object into the filesystem .How can I do this ?
What's the way to get actual number of pages from the document object without saving into the file system ? If the document object API cannot give the actual number of pages ,then why do you expose such an API ?
Expecting a reponse ASAP.
Regards
Praveen
Code sample :
public static void main(String[] args) throws FileNotFoundException {
java.util.Locale locale1 = new java.util.Locale("en");
java.util.Locale.setDefault(locale1);
License lic = new License();
lic.setLicense(new FileInputStream("d:\\work\\Aspose.Total.Java.lic"));
// Added document
Document doc = new com.aspose.pdf.Document();
PageInfo pageInfo = doc.getPageInfo();
MarginInfo marginInfo = pageInfo.getMargin();
marginInfo.setLeft(37);
marginInfo.setRight(37);
marginInfo.setTop(90);
marginInfo.setBottom(37);
pageInfo.isLandscape(true);
com.aspose.pdf.Table table = new com.aspose.pdf.Table();
table.setRepeatingRowsCount(1);
table.setRepeatingRowsStyle(new TextState(Color.GREEN));
table.setColumnWidths("50 100");
// added page.
Page curPage = doc.getPages().add();
// adding body contents
for (int i = 0; i < 100; i++) {
if (i == 0) {
com.aspose.pdf.Row row = table.getRows().add();
com.aspose.pdf.Cell cell1 = row.getCells().add();
cell1.getParagraphs().add(
new com.aspose.pdf.TextFragment("Heading 1"));
com.aspose.pdf.Cell cell2 = row.getCells().add();
cell2.getParagraphs().add(
new com.aspose.pdf.TextFragment("Heading 2"));
} else {
com.aspose.pdf.Row row = table.getRows().add();
com.aspose.pdf.Cell cell1 = row.getCells().add();
cell1.getParagraphs().add(
new com.aspose.pdf.TextFragment("Content 1"));
com.aspose.pdf.Cell cell2 = row.getCells().add();
cell2.getParagraphs().add(
new com.aspose.pdf.TextFragment("Content 2"));
}
}
table.getMargin().setTop(10);
curPage.getParagraphs().add(table);
System.out.println("Total Pages "+ doc.getPages().size());
doc.save("pagessizeissue.pdf");
}
private static com.aspose.pdf.Table getSampleTable(String content1,String content2) {
com.aspose.pdf.Table table = new com.aspose.pdf.Table();
com.aspose.pdf.Row row = table.getRows().add();
com.aspose.pdf.Cell cell1 = row.getCells().add();
cell1.getParagraphs().add(new com.aspose.pdf.TextFragment(content1));
com.aspose.pdf.Cell cell2 = row.getCells().add();
cell2.getParagraphs().add(new com.aspose.pdf.TextFragment(content2));
return table;
}