try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("Report.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
document.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
這是我寫在NetBeans的代碼,但我在第一線得到錯誤:文檔是抽象的;不能被實例化
error 1 in 1st line: Document is abstract; cannot be instantiated
error 2 in 2nd line cannot find symbol ,symbol: variable PdfWriter
PdfWriter是由第三方罐子提供的還是由您自己提供的? –
PdfWriter由第三方罐子提供 – user2279470
所以有兩個問題!首先,在編譯代碼時檢查第三方jar是否在類路徑中。其次,檢查API類的Document以瞭解如何創建新文檔,我猜這個對象應該由一些Factory類創建。 –