Issue
I'm working on an Spring Boot application in which I would like to create a pdf when the user presses a button. I'm using apache.pdfbox and vandeseer.easytable in order to generate the PDF. So far so good.
But when I hit the button to generate the PDF (see the function below), it just gives me an "java.lang.NoClassDefFoundError: org/vandeseer/easytable/structure/Table" for where I start building the table ("Table.TableBuilder myTable....).
Have I missed something in implementing easyTable? Generating an empty PDF was working before I added in easyTable...
public class pdfGeneration {
// Where we actually want to generate and print the receipt
public static void generatePDF(Cart cart) throws IOException {
// Creating the document and an empty page
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
// Build the table
Table.TableBuilder myTable = Table.builder()
.addColumnsOfWidth(100, 50, 50)
.fontSize(8)
.borderColor(Color.RED);
myTable.addRow(Row.builder()
.add(TextCell.builder().text("Productname").build())
.add(TextCell.builder().text("Quantity").build())
.add(TextCell.builder().text("Price").build())
.build());
// Close the contentStream, save and close the document
contentStream.close();
document.save("C:/Users/yourusername/Desktop/my_doc.pdf");
document.close();
}
}
Solution
Do you have the following dependency in your pom.xml
<dependency>
<groupId>com.github.vandeseer</groupId>
<artifactId>easytable</artifactId>
<version>0.8.5</version>
</dependency>
Answered By - SMA
Answer Checked By - Senaida (JavaFixing Volunteer)