java生成pdf盖章合同_通过Java组件iText生成PDF报表或合同,完成pdf上传,预览,存入数据库...

package com.ymy.util;/*@author ymy

@DESCRIPTION ${DESCRIPTION}

@create 2019/4/12*/

import com.ymy.model.*;importjava.io.ByteArrayOutputStream;importjava.io.File;importjava.io.FileOutputStream;importjava.util.ArrayList;importcom.itextpdf.text.pdf.AcroFields;importcom.itextpdf.text.pdf.BaseFont;importcom.itextpdf.text.pdf.PdfReader;importcom.itextpdf.text.pdf.PdfStamper;public classPDFTempletTicket {privateString templatePdfPath;privateString ttcPath;privateString targetPdfpath;privateTicket ticket;publicPDFTempletTicket() {super();

}publicPDFTempletTicket(String templatePdfPath, String ttcPath,

String targetPdfpath, Ticket ticket) {this.templatePdfPath=templatePdfPath;this.ttcPath=ttcPath;this.targetPdfpath=targetPdfpath;this.ticket=ticket;

}public void templetTicket(File file) throwsException {

PdfReader reader= newPdfReader(templatePdfPath);

ByteArrayOutputStream bos= newByteArrayOutputStream();

PdfStamper ps= newPdfStamper(reader, bos);/*使用中文字体*/BaseFont bf= BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);/*BaseFont bf = BaseFont.createFont(PDFTicket.class.getResource("/") + "org/csun/ns/util/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);*/ArrayList fontList = new ArrayList();

fontList.add(bf);

AcroFields s=ps.getAcroFields();

s.setSubstitutionFonts(fontList);

s.setField("productName",ticket.getProductName());

s.setField("name",ticket.getName());

s.setField("idCard",ticket.getIdCard());

s.setField("tel",ticket.getTel());

s.setField("address",ticket.getAddress());

ps.setFormFlattening(false);

ps.close();

FileOutputStream fos= newFileOutputStream(file);

fos.write(bos.toByteArray());

fos.close();

}/***@returnthe templatePdfPath*/

publicString getTemplatePdfPath() {returntemplatePdfPath;

}/***@paramtemplatePdfPath the templatePdfPathto set*/

public voidsetTemplatePdfPath(String templatePdfPath) {this.templatePdfPath=templatePdfPath;

}/***@returnthe ttcPath*/

publicString getTtcPath() {returnttcPath;

}/***@paramttcPath the ttcPath to set*/

public voidsetTtcPath(String ttcPath) {this.ttcPath=ttcPath;

}/***@returnthe targetPdfpath*/

publicString getTargetPdfpath() {returntargetPdfpath;

}/***@paramtargetPdfpath the targetPdfpath toset*/

public voidsetTargetPdfpath(String targetPdfpath) {this.targetPdfpath=targetPdfpath;

}/***@returnthe ticket*/

publicTicket getTicket() {returnticket;

}/***@paramticket the ticket to set*/

public voidsetTicket(Ticket ticket) {this.ticket=ticket;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值