|
@@ -18,6 +18,7 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class PdfAddimgUtil {
|
|
|
+ private static final double INCH_TO_CM = 2.54;
|
|
|
|
|
|
public static void pdfAddImgInfo(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap) throws Exception {
|
|
|
String file_path = FileUtils.getSysLocalFileUrl();
|
|
@@ -143,7 +144,7 @@ public class PdfAddimgUtil {
|
|
|
reader.close();
|
|
|
}
|
|
|
//后管新增电签预览添加图片信息方法
|
|
|
- public static void PrepdfAddImgInfoNew(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap ,String signImg) throws Exception {
|
|
|
+ public static void PrepdfAddImgInfoNew(String pdfUrl, String keyword, Map<Long, TextdictInfo> textMap ,String signImg,double wide , double hign) throws Exception {
|
|
|
File pdfFile = new File(pdfUrl);
|
|
|
byte[] pdfData = new byte[(int) pdfFile.length()];
|
|
|
FileInputStream inputStream = null;
|
|
@@ -181,14 +182,14 @@ public class PdfAddimgUtil {
|
|
|
pyzby = Func.toFloat(textdictInfo.getPyzby());
|
|
|
type = textdictInfo.getType()+"";
|
|
|
}
|
|
|
- PreGaizhang(pdfFile, new File(pdfUrl), (int) position[0], position[1], position[2], signImg,pyzbx,pyzby,type);
|
|
|
+ PreGaizhang(pdfFile, new File(pdfUrl), (int) position[0], position[1], position[2], signImg,pyzbx,pyzby,type,wide,hign);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//后管新增电签预览盖章方法
|
|
|
- public static void PreGaizhang(File src, File dest, int page, float x, float y, String imagePath,float pyzbx,float pyzby,String type) throws Exception {
|
|
|
+ public static void PreGaizhang(File src, File dest, int page, float x, float y, String imagePath,float pyzbx,float pyzby,String type,double wide, double hign) throws Exception {
|
|
|
// 读取模板文件
|
|
|
InputStream input = new FileInputStream(src);
|
|
|
PdfReader reader = new PdfReader(input);
|
|
@@ -207,15 +208,14 @@ public class PdfAddimgUtil {
|
|
|
|
|
|
// 读图片
|
|
|
Image image = Image.getInstance(imagePath);
|
|
|
-
|
|
|
// 获取操作的页面
|
|
|
PdfContentByte under = stamper.getOverContent(page);
|
|
|
// 添加图片
|
|
|
|
|
|
- /*// 设置图片的新宽度和高度
|
|
|
- float newWidth = 75f; // 新的宽度
|
|
|
- float newHeight = image.getScaledHeight() * (newWidth / image.getScaledWidth()); // 根据宽度计算高度
|
|
|
- image.scaleAbsolute(newWidth, newHeight); // 设置图片的新尺寸*/
|
|
|
+ // 设置图片的新宽度和高度
|
|
|
+ int newWidth = cmToPx(wide);
|
|
|
+ int newHeight = cmToPx(hign);
|
|
|
+ image.scaleAbsolute(newWidth, newHeight); // 设置图片的新尺寸
|
|
|
//调整图片尺寸
|
|
|
image.setAbsolutePosition(x, y);
|
|
|
under.addImage(image);
|
|
@@ -223,7 +223,15 @@ public class PdfAddimgUtil {
|
|
|
stamper.close();
|
|
|
reader.close();
|
|
|
}
|
|
|
-
|
|
|
+ public static int cmToPx(double cm) {
|
|
|
+ double pixelsPerCm = 90 / INCH_TO_CM;
|
|
|
+ return (int) Math.round(cm * pixelsPerCm);
|
|
|
+ }
|
|
|
+ public static double pxToCm(int px) {
|
|
|
+ double cmPerPixel = INCH_TO_CM / 90;
|
|
|
+ //保留两位小数
|
|
|
+ return Math.round(px * cmPerPixel * 100) / 100.0;
|
|
|
+ }
|
|
|
/**
|
|
|
* 【功能描述:添加图片和文字水印】 【功能详细描述:功能详细描述】
|
|
|
*
|