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

Okay so I tried it out for you. My previous answer was incorrect, declaring the file first works as well. I think that your table declaration is wrong. You set it to 9 columns, but you only fill 5 of them. If you would change your columnssize of the headerTable to 5 that should fix it.


I guess Aries51's solution worked for you. One additional note: you dont seem to catch your exceptions at all. A big try-catch around everything in your main-method (or a throwing main-method) is not the way to use exceptions. For example you should wrap a try-catch around Aries51's suggestion of PdfWriter.getInstance(document, new FileOutputStream("c:/sample.pdf")); because at some point you will replace the static c:/... sample string with a string the user enters at runtime. An exception should tell you if that file is writable or if it exists at all (user can enter bogus).


You get this error when the compiler does not get any meaningful information to write to your file. I suggest trying to add this line after open()

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

It should work

Tags:

Java

Itext