Document is abstract; cannot be instantiated

2019-07-20 02:02发布

问题:

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

This is the code i have written in NetBeans but i am getting error in first line:

error 1 in 1st line: Document is abstract; cannot be instantiated 

error 2 in 2nd line cannot find symbol ,symbol: variable PdfWriter

回答1:

You are clearly importing the wrong Document class, the correct import is com.itextpdf.text.Document, update your import statements and this will be fixed.



回答2:

To resolve this problem, you have to copy and paste this import statement: it will work 100% import com.itextpdf.text.Document;



回答3:

Download itext-5.1.3 it will work 100% sure . :) and add all the JAR into your project . I faced the same problem and solved it.



标签: itext