0

I am getting a The document has no pages. runtime error in this program...

public class Windows {

    public static void main(String[] args) throws FileNotFoundException, DocumentException {

       java.io.File f = new java.io.File("c:/temp/text.pdf");
       java.io.FileOutputStream fo = new java.io.FileOutputStream(f);

       com.itextpdf.text.Document d = new com.itextpdf.text.Document(PageSize.A5, 50, 50, 50, 50);

       PdfWriter pw = PdfWriter.getInstance(d, fo);
       d.open();

       Boolean b0 = d.newPage();
       Boolean b1  =  d.addAuthor("Tamil Selvan");

       d.addCreator("Tamil Selvan");
       d.addHeader("Tamil Selvan Header name", "Header Content");
       d.addKeywords("These are the keywords for the document");
       d.addSubject("These are the subjects for the Document");
       d.addTitle("The Title Of the Document");

       d.close();

       System.out.println("Is the Documnet is Opened "+b0); 
       System.out.println("Is the Documnet is Working "+b1); 
    };
}

How can I run this?

wattostudios
  • 8,666
  • 13
  • 43
  • 57

1 Answers1

0

I believe the problem here is that you have provided metadata for the pdf, but no actual body or content for the pdf.

For example, you can try

d.add(new Paragraph("Some random text"));

and seeing if this addresses the error you are facing.

demongolem
  • 9,474
  • 36
  • 90
  • 105