|
@@ -142,6 +142,87 @@ public class PdfAddimgUtil {
|
|
stamper.close();
|
|
stamper.close();
|
|
reader.close();
|
|
reader.close();
|
|
}
|
|
}
|
|
|
|
+ //后管新增电签预览添加图片信息方法
|
|
|
|
+ public static void PrepdfAddImgInfoNew(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap ,String signImg) throws Exception {
|
|
|
|
+ File pdfFile = new File(pdfUrl);
|
|
|
|
+ byte[] pdfData = new byte[(int) pdfFile.length()];
|
|
|
|
+ FileInputStream inputStream = null;
|
|
|
|
+ try {
|
|
|
|
+ inputStream = new FileInputStream(pdfFile);
|
|
|
|
+ inputStream.read(pdfData);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw e;
|
|
|
|
+ } finally {
|
|
|
|
+ if (inputStream != null) {
|
|
|
|
+ try {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<PDFIndexInfo> positions = findKeywordPostions(pdfData, keyword);
|
|
|
|
+
|
|
|
|
+ System.out.println("total:" + positions.size());
|
|
|
|
+ if (positions != null && positions.size() > 0) {
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < positions.size(); i++) {
|
|
|
|
+
|
|
|
|
+ PDFIndexInfo pdfIndexInfo = positions.get(i);
|
|
|
|
+ float[] position = pdfIndexInfo.getDataInfo();
|
|
|
|
+ TextdictInfo textdictInfo = textMap.get(Func.toLong(pdfIndexInfo.getPkeyid()));
|
|
|
|
+ float pyzbx = 0;
|
|
|
|
+ float pyzby = 0;
|
|
|
|
+ String type ="2";
|
|
|
|
+ if(textdictInfo!=null){
|
|
|
|
+ pyzbx = Func.toFloat(textdictInfo.getPyzbx());
|
|
|
|
+ pyzby = Func.toFloat(textdictInfo.getPyzby());
|
|
|
|
+ type = textdictInfo.getType()+"";
|
|
|
|
+ }
|
|
|
|
+ PreGaizhang(pdfFile, new File(pdfUrl), (int) position[0], position[1], position[2], signImg,pyzbx,pyzby,type);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //后管新增电签预览盖章方法
|
|
|
|
+ public static void PreGaizhang(File src, File dest, int page, float x, float y, String imagePath,float pyzbx,float pyzby,String type) throws Exception {
|
|
|
|
+ // 读取模板文件
|
|
|
|
+ InputStream input = new FileInputStream(src);
|
|
|
|
+ PdfReader reader = new PdfReader(input);
|
|
|
|
+ PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
|
|
|
|
+ Rectangle pageSize = reader.getPageSize(1);
|
|
|
|
+ float height = pageSize.getHeight();
|
|
|
|
+ float width = pageSize.getWidth();
|
|
|
|
+ if(type.equals("6")){
|
|
|
|
+ x = width * x - 27+pyzbx;
|
|
|
|
+ y = height - height * y - 30+pyzby;
|
|
|
|
+ imagePath = "/Users/hongchuangyanfa/Desktop/print/ht1234567890.png";
|
|
|
|
+ }else{
|
|
|
|
+ x = width * x - 20+pyzbx;
|
|
|
|
+ y = height - height * y - 8+pyzby;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 读图片
|
|
|
|
+ Image image = Image.getInstance(imagePath);
|
|
|
|
+
|
|
|
|
+ // 获取操作的页面
|
|
|
|
+ PdfContentByte under = stamper.getOverContent(page);
|
|
|
|
+ // 添加图片
|
|
|
|
+
|
|
|
|
+ /*// 设置图片的新宽度和高度
|
|
|
|
+ float newWidth = 75f; // 新的宽度
|
|
|
|
+ float newHeight = image.getScaledHeight() * (newWidth / image.getScaledWidth()); // 根据宽度计算高度
|
|
|
|
+ image.scaleAbsolute(newWidth, newHeight); // 设置图片的新尺寸*/
|
|
|
|
+ //调整图片尺寸
|
|
|
|
+ image.setAbsolutePosition(x, y);
|
|
|
|
+ under.addImage(image);
|
|
|
|
+ // 假设的under.addImage方法,需要传入图片路径和大小参数
|
|
|
|
+ stamper.close();
|
|
|
|
+ reader.close();
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 【功能描述:添加图片和文字水印】 【功能详细描述:功能详细描述】
|
|
* 【功能描述:添加图片和文字水印】 【功能详细描述:功能详细描述】
|