ExceptionConverter: java.io.IOException: The document has no pages. i am using iText

when i execute the code below

File f = new File("c:/sample.pdf");
PdfWriter.getInstance(document, new FileOutputStream(f));
document.open();
System.out.println("opening the document..");
PdfPTable headerTable=new PdfPTable(9);
PdfPCell cellValue = new PdfPCell(new Paragraph("Header 1"));
cellValue.setColspan(1);
headerTable.addCell(cellValue);
cellValue = new PdfPCell(new Paragraph("Header 2"));
headerTable.addCell(cellValue);
cellValue = new PdfPCell(new Paragraph("Header 3"));
headerTable.addCell(cellValue);
cellValue = new PdfPCell(new Paragraph("Header 4"));
headerTable.addCell(cellValue);

PdfPTable subHeaderTable = new PdfPTable(3);
PdfPCell subHeadingCell = new PdfPCell(new Paragraph("Header 5"));
subHeadingCell.setColspan(3);
subHeaderTable.addCell(subHeadingCell);
subHeaderTable.addCell("Sub heading 1");
subHeaderTable.addCell("Sub heading 2"); 
subHeaderTable.addCell("Sub heading 3");

headerTable.addCell(subHeaderTable);

document.add(headerTable);
document.close();

I get below exceptions. please, help

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)

PLEASE HELP FRIENDS. THANKS IN EXTENSION

+6
source share
7 answers

Ok, so I tried this for you. My previous answer was wrong and the file declaration works first. I think your table declaration is incorrect. You set it to 9 columns, but you fill in only 5 of them. If you change your headerTable column to 5, that should fix it.

+13
source

, Aries51 . : , , . ( ) - . , try-catch Aries51 PdfWriter.getInstance(document, new FileOutputStream("c:/sample.pdf"));, - c:/... , . , ( ).

+2

, - . open()

document.add(new Chunk(""));

+2

File f = new File("c:/sample.pdf");
PdfWriter.getInstance(document, new FileOutputStream(f));

PdfWriter.getInstance(document, new FileOutputStream("c:/sample.pdf"));

, , ...

0

. pdf netbeans, .

, , , "watermark.png", PDF , "distbuild.jar".

"watermark.png" jar, .

, jar.

0

PDF. .

0

PdfPTable patTable = AgsiPdfPUtil.getTable(10);//

10 , 10

0

All Articles