Spring Boot
[spring boot] PDF 출력 - iText7_02(TEXT)
도쿄아재
2023. 2. 8. 11:16
반응형
import java.io.File;
import java.io.FileNotFoundException;
import com.itextpdf.io.IOException;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Text;
public class Itext7_04 {
public static void main(String[] args) throws IOException {
try {
File file = new File("iText7_Text.pdf");
PdfWriter pdfWriter = new PdfWriter(file);
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
Paragraph paragraph = new Paragraph();
Text text1 = new Text("BASIC Text ");
paragraph.add(text1);
Text text2 = new Text("Bold Text ");
text2.setBold();
paragraph.add(text2);
Text text3 = new Text("Underline Text ");
text3.setUnderline();
paragraph.add(text3);
Text text4 = new Text("LineThrough Text ");
text4.setItalic();
text4.setLineThrough();
paragraph.add(text4);
document.add(paragraph);
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
반응형