I need to generate a Pdf document from some data that is located in a database and I came across iTEXT 7. I just started my first Maven project on Netbeans (started with a basic hello world) and this is the output:
Building mavenproject2 1.0-SNAPSHOT
Exception in thread "main" java.lang.NullPointerException
at com.mycompany.mavenproject2.class2.main(class2.java:18) BUILD FAILURE [Help 1]To see the full stack trace of the errors, re-run Maven with the -e switch. Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
CODE :
package com.mycompany.mavenproject2;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import java.io.*;
public class class2 {
public static void main(String args[]) throws FileNotFoundException
{
File file = new File("hello.pdf");
file.getParentFile().mkdirs();
PdfWriter writer = new PdfWriter("hello.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();
}
}
pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>mavenproject2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>itext</id>
<name>iText Repository - releases</name>
<url>https://repo.itextsupport.com/releases</url>
</repository>
</repositories>
<dependencies>
<!-- add all iText Core modules -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.0.3</version>
<type>pom</type>
</dependency>
<!-- pdfSweep -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>cleanup</artifactId>
<version>1.0.2</version>
</dependency>
<!-- pdfCalligraph -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>typography</artifactId>
<version>1.0.2</version>
</dependency>
<!-- pdfInvoice -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>zugferd</artifactId>
<version>1.0.1</version>
</dependency>
<!-- pdfHTML -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>1.0.0</version>
</dependency>
<!-- pdfXFA -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfxfa</artifactId>
<version>1.0.1</version>
</dependency>
<!-- iText 7 License Key Library -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-licensekey</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>