So I am trying to generate a report that may contain many pages depending upon the user input and data.
Similar error was summarized here but its not seen to be the actual solution of the problem.
My function:
public void generateReport()
{
final String path = "/sdcard/testreport.pdf";
try
{
Document document = new Document();
writer = PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
// many lines code related to report generation
writer.setOpenAction(action);
status = GetReport(document);
document.close(); //RunTimeException here.
}
catch (Exception e)
{
e.printStackTrace();
}
But I am getting RunTimeException as-
Log
04-16 19:34:01.928: W/System.err(14248): java.lang.RuntimeException: The page 1 was requested but the document has only 0 pages.
04-16 19:34:01.929: W/System.err(14248): at com.itextpdf.text.pdf.PdfWriter.close(PdfWriter.java:1208)
04-16 19:34:01.929: W/System.err(14248): at com.itextpdf.text.pdf.PdfDocument.close(PdfDocument.java:776)
04-16 19:34:01.929: W/System.err(14248): at com.itextpdf.text.Document.close(Document.java:420)
04-16 19:34:01.929: W/System.err(14248): at com.wassap.main.ReportsActivity.generateReport(ReportsActivity.java:541)
I am not getting the clue as of how to close the document only if to know in advance if the page is there.