java 根据pdf坐标填入内容

/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.test;

import org.apache.shiro.crypto.AesCipherService;

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Iterator;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;

public class RememberMeKeyGen {
	static String  gouimg = "D:\\工作文件\\donghao\\开户\\gou.png";
	static int y = 790;
	public static void main(String[] args) throws Exception{
		genPdf();
	}

	public static void genPdf() throws Exception {
		PdfReader reader = new PdfReader("D:\\工作文件\\donghao\\开户\\kh.pdf");
		PdfStamper stamper = new PdfStamper(reader,
				new FileOutputStream("D:\\工作文件\\donghao\\开户\\111.pdf"));
		BaseFont mingliu = BaseFont.createFont("D:\\工作文件\\donghao\\开户\\mingliu.ttc,0",
				BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
		BaseFont air = BaseFont.createFont("D:\\工作文件\\donghao\\开户\\calibri.ttf", BaseFont.IDENTITY_H,
				BaseFont.NOT_EMBEDDED);
		Font fontMingliu = new Font(mingliu, 10);
		Font fontair = new Font(air, 10);
		String gou = "";
//				"/Users/heyanchao/Desktop/hyc/img/font/gou.jpg";
		String goukuang = "";
//				"/Users/heyanchao/Desktop/hyc/img/font/gou_kuang.jpg";

		for (int i = 1; i <= reader.getNumberOfPages(); i++) {
			PdfContentByte over = stamper.getOverContent(i);
			if(i ==1) {
				setPage1(over,fontMingliu);
			}

		}

		stamper.close();
	}

	public static void setPage1(PdfContentByte over, Font fontMingliu) throws IOException, DocumentException {
		//		財務狀況
		addImg(over, gouimg, 44, y-93);
		addImg(over, gouimg, 153, y-93);
	
	}
	public static void addtext(PdfContentByte over, Font font, String content, float w, float h) {
		if (content == null) {
			content = "";
		}
		over.beginText();
		over.setFontAndSize(font.getBaseFont(), font.getSize());
		over.setColorFill(BaseColor.BLACK);
		over.setTextMatrix(w, h);
		over.showText(content);
		over.endText();
	}

	public static void addImg(PdfContentByte over, String gou, float w, float h)
			throws MalformedURLException, IOException, DocumentException {
		Image tongxun = Image.getInstance(gou);
		tongxun.setAbsolutePosition(w, h);// 同上 123, 481.7f
		tongxun.scaleToFit(6, 6);// 大小
		over.addImage(tongxun);
	}
	public static void addImg3(PdfContentByte over, String gou, float w, float h)
			throws MalformedURLException, IOException, DocumentException {
		Image tongxun = Image.getInstance(gou);
		tongxun.setAbsolutePosition(w, h);// 同上 123, 481.7f
		tongxun.scaleToFit(50, 30);// 大小
		over.addImage(tongxun);
	}

	public static void addImg2(PdfContentByte over, String gou, float w, float h)
			throws MalformedURLException, IOException, DocumentException {
		Image tongxun = Image.getInstance(gou);
		tongxun.setAbsolutePosition(w, h);// 同上 123, 481.7f
		tongxun.scaleToFit(8, 8);// 大小
		over.addImage(tongxun);
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值