Create PDF with itext7 ~ Hello World ~

Create PDF with itext7

There is a library called itext7 that creates PDF, but there are few Japanese documents, so I will summarize it. I will do it with eclipse + gradle.

build.gradle settings

build.gradle


dependencies {
~ Abbreviation ~
    //Added itext7
    implementation 'com.github.itext.itext7:layout:7.1.4'
    //Added Japanese font for itext7
    implementation 'com.github.itext.itext7:font-asian:7.1.4'
    //Added slf4j
    implementation 'org.slf4j:slf4j-log4j12:1.7.21'
}
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

If you do not read "slf4j" as well, the following error will occur.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Run Hello World

HelloWorld.java


import java.io.File;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

public class HelloWorld {
    public static void main(String[] args) throws Exception {
        //Initialize PDF writer
        PdfWriter writer = new PdfWriter(new File("HelloWorld.pdf"));
 

        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(writer);
 
        // Initialize document
        Document document = new Document(pdf);
 
        //Add paragraph to the document
        document.add(new Paragraph("Hello World!"));
 
        //Close document
        document.close();
   }
}

Next time: Let's speak Japanese

Now, if you replace the "Hello World!" Part of the tutorial with Japanese ... that? Is it pure white? Next time starts from that area!

Recommended Posts

Create PDF with itext7 ~ Hello World ~
Hello World with Micronaut
Hello World with Spring Boot
Hello World with Spring Boot!
Hello World with VS Code!
Hello World with Spring Boot
Hello World with SpringBoot / Gradle
Hello, World! With Asakusa Framework!
Create PDF with itext7-Free layout: Text-
Create PDF with itext7-Free layout: Table-
Until "Hello World" with Spring Boot
Hello world with Kotlin and JavaFX
Hello World with Docker and C
Create a Hello World web app with Spring framework + Jetty
Hello World with GlassFish 5.1 + Servlet + JSP
"Hello world" for ImageJ with Eclipse
Hello World with GWT 2.8.2 and Maven
[Swift] Create a project with Xcode (ver 12.1) and display "Hello, World!"
Hello world with Java template engine Thymeleaf
Java development with Codenvy: Hello World! Run
"Hello, World!" With Kotlin + CLI in 5 minutes
Hello world with Kotlin and Tornado FX
How Spring Security works with Hello World
(IntelliJ + gradle) Hello World with Spring Boot
Read "Hello world"
Java Hello World
Sample to create PDF from Excel with Ruby
Hello World with JavaFX 11 (OpenJFX) in Liberica JDK 11
Hello world! With Spring Boot (Marven + text editor)
Hello World at explosive speed with Spring Initializr! !! !!
Run JSP Hello World with Tomcat on Docker
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Show a simple Hello World with SpringBoot + IntelliJ
Try to display hello world with spring + gradle
Easy to display hello world with Rails + Docker
Try create with Trailblazer
"Hello World" in Java
Hello World (REST API) with Apache Camel + Spring Boot 2
Java Learning (1)-Hello World
Read System.out.println ("hello, world")
Let's write Hello World
Hello world in node.js
Studying Java-Part 1-Hello World
Hello World on WebAssembly
Hello World (console app) with Apache Camel + Spring Boot 2
[Java] One type of alphabet prohibited With binding Hello, world! [Binding]
Hello World with Ruby extension library for the time being
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ① ~ Hello World ~
Create XML-RPC API with Wicket
Paging PDF with Java + PDFBox.jar
Create a playground with Xcode 12
Java beginners read Hello World
Create microservices with Spring Boot
Until you run Hello World of JavaFX with VS Code + Gradle
Try Hello World with the minimum configuration of Heroku Java spring-boot
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy