2012-06-28 51 views
0

我得到一個The document has no pages.運行時錯誤在這個程序...如何清除此錯誤iTextPdf文檔錯誤?

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); 
    }; 
} 

我如何運行呢?

回答

0

我相信這裏的問題是您已經提供了pdf的元數據,但沒有提供PDF的實際內容或內容。

例如,你可以嘗試

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

,看是否這解決您所面對的錯誤。