时间的法外狂徒

导航

itextpdf5生成document生成pdf的简单dome

package dbzx.pdf;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.junit.Test;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class CreateSimplePdf {
    
    @Test
    public void createSimplePdf() throws FileNotFoundException, DocumentException {
        String path = "E:/demo/pdfCreat/"+System.currentTimeMillis()+".pdf";//输出pdf的路径
        Document doc = new Document();
        PdfWriter.getInstance(doc, new FileOutputStream(path));
        doc.open();
        doc.add(new Paragraph("test"));//在pdf中打印文本
        doc.close();
        
        
    }
}

 

posted on 2019-10-30 11:15  抄手砚  阅读(1846)  评论(0编辑  收藏  举报