Hi, I'm using PdfPTable, when a cell is too large--more than a page, throws an exception like this:
ExceptionConverter: java.io.IOException: The document has no pages.
        at com.lowagie.text.pdf.PdfPages.writePageTree(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
        at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
        at com.lowagie.text.Document.close(Unknown Source)
        at com.gsk.harp.util.PdfTest.main(PdfTest.java:65)
Exception in thread "main"

My program is as below:

public class PdfTest {
  public static void main(String[] args) {

        Document document = new Document(PageSize.A4.rotate(), 36, 36, 36, 36);
    try {

      PdfWriter writer =
        PdfWriter.getInstance(
          document,
          new FileOutputStream("C:\\doc\\BaseDoc1.pdf"));

      document.open();
          PdfPTable table = new PdfPTable(3);
          table.addCell("test1");

        //add a large cell
          StringBuffer sb = new StringBuffer();
          for(int i=0; i<50; i++) {
           sb.append("testtest\n");
          }
          table.addCell(sb.toString());

        //add a large nested table
          PdfPTable table1 = new PdfPTable(1);
          for(int i=0; i<30; i++) {          
           table1.addCell("test3");
          }
          PdfPCell pcell = new PdfPCell(table1);
          pcell.setPadding(0.0f);
          table.addCell(pcell);
          document.add(table);

    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
  }

}

Reply via email to