pdf生成功能

package com.fineway.hcs.file.util;
import java.io.*;

import java.text.SimpleDateFormat;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.*;

public class test {

public static void main(String[] args) throws IOException, DocumentException {

    // 模板路径  C:/hhywk/lib/success_temp.pdf
    String templatePath = "C:/hhywk/lib/success_temp.pdf";

// String templatePath = “D:/fail.pdf”;
// 生成的新文件路径
// String newPDFPath = “D:/success_temp.pdf”;
String targetPath = “C:/hhywk/lib/success.pdf”;

    // 读取模板文件

// InputStream input = new FileInputStream(new File(templatePath));
// PdfReader reader = new PdfReader(input);
// PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(targetPath));
// 提取pdf中的表单
// AcroFields form = stamper.getAcroFields();
// form.addSubstitutionFont(BaseFont.createFont(“STSong-Light”,“UniGB-UCS2-H”, BaseFont.NOT_EMBEDDED));
BaseFont bf = BaseFont.createFont(“C:\hhywk\lib\simsun.ttf”,
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(bf, 12, Font.NORMAL);
// form.addSubstitutionFont(bf);
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(“C:/hhywk/lib/success.pdf”));
String text1 = "啊发生的发球特工是大哥是法国时的风格是This is the quite popular True Type "+new java.util.Date();
document.open();
document.add(new Paragraph(text1, font));
document.add(new Paragraph(text1, font));
document.close();
// stamper.close();
// reader.close();
}

}

你可能感兴趣的:(pdf生成功能)