Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document is abstract; cannot be instantiated

Tags:

itext

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
like image 963
user2279470 Avatar asked Dec 01 '25 06:12

user2279470


2 Answers

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.

like image 147
Maurício Linhares Avatar answered Dec 04 '25 10:12

Maurício Linhares


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

like image 27
Bienfait Rukundo Avatar answered Dec 04 '25 08:12

Bienfait Rukundo