打印pdf itext 的多个pdf合并并删除旧的pdf文件

这篇博客介绍如何使用iText库在Java中合并多个PDF文件,并在合并完成后删除原始PDF,以节省存储空间。主要涉及创建Document、PdfWriter、PdfCopy对象,以及处理PdfReader和FileOutputStream。
摘要由CSDN通过智能技术生成

有时候我们打印pdf时需要生成多个pdf文件,最后合成一个新的pdf来打印,我们又嫌这么多pdf占内存所以合并后把之前的pdf删除掉。

/**
* 打印出库单(导出pdf文件)

* @throws IOException
* @method: printChuku() 
* @TODO: void
*/
public void printChuku() {
try {
//刊的状态 0常用,1不常用
Integer pub_state = getParaToInt("pub_state", 0);
String start = getPara("start");
String end = getPara("end");
//查询每期的每版的某个客户数量之和
String sql = "SELECT SUM(o.total_number) number,SUM(o.sub_number)  suber,"
+ "SUM(o.free_number) freenum, o.*,c.*,ou.*,u.user_xingming FROM ordertable o LEFT JOIN customers c ON o.cus_id=c.cus_id "
+ "LEFT JOIN USER u ON o.user_id=u.user_id left join outbound ou on o.out_id=ou.out_id "
+ " where o.ord_status=2 and o.out_id IS NOT NULL";
//查询业务员和客户
String sql1 = " SELECT o.*,c.*,ou.*,u.user_xingming FROM ordertable o LEFT JOIN customers c ON o.cus_id=c.cus_id "
+ "LEFT JOIN USER u ON o.user_id=u.user_id left join outbound ou on o.out_id=ou.out_id  where  o.ord_status=2  and o.out_id IS NOT NULL";
if (start != null && start != "" && end != null && end != "") {
String w = " and ou.out_date >='" + start + "' and ou.out_date<='" + end + "' ";
sql = sql + w;
sql1 = sql1 + w;
}
String osql = sql + " and o.pub_id in (select pub_id from publish where pub_state=" + pub_state + ")" + " GROUP BY ou.out_code";
sql = sql + " and o.pub_id in (select pub_id from publish where pub_state=" + pub_state + ")"
+ " GROUP BY ou.out_code,o.iss,o.edi_id,c.cus_name ORDER BY ou.out_id DESC";
sql1 = sql1 + " and o.pub_id in (select pub_id from publish where pub_state=" + pub_state + ") "
+ "GROUP BY ou.out_code,c.cus_name,o.iss ORDER BY ou.out_id DESC";
List<Ordertable> oList = Ordertable.dao.find(sql);
List<Ordertable> oList1 = Ordertable.dao.find(sql1);
List<Outbound> chuku = Outbound.dao.find(osql);
//获取刊等信息
List<Publish> plist = Publish.dao.find("select * from publish where pub_state=" + pub_state);
Font font = null;
Font cellFont = null;
PdfPTable table = null;
PdfPHeaderCell header = null;
PdfPCell cell = null;
String[] pdf = new String[chuku.size()];
for (int k = 0; k < chuku.size(); k++) {
pdf[k] = PathKi

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值