com.github.bjlhx15.common.pdf.JavaToPdfCN Maven / Gradle / Ivy
package com.github.bjlhx15.common.pdf;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class JavaToPdfCN {
private static final String DEST = "/Users/lihongxu6/IdeaProjects/common/common-pdf/target/HelloWorldCN.pdf";
private static final String FONT = "simhei.ttf";
public static void main(String[] args) throws FileNotFoundException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
document.open();
Font f1 = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
document.add(new Paragraph("hello world,我是李宏旭", f1));
document.close();
writer.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy