|
@ -77,22 +77,25 @@ public class PdfModelUitl { |
|
|
if(null!=field) { |
|
|
if(null!=field) { |
|
|
Rectangle rtl = field.getWidgets().get(0).getRectangle().toRectangle(); // 获取表单域的xy坐标
|
|
|
Rectangle rtl = field.getWidgets().get(0).getRectangle().toRectangle(); // 获取表单域的xy坐标
|
|
|
field.setFont(defaultFont()); |
|
|
field.setFont(defaultFont()); |
|
|
field.setFontSize(12); |
|
|
if(Optional.ofNullable(field.getFontSize()).isEmpty()){ |
|
|
|
|
|
field.setFontSize(16); |
|
|
|
|
|
} |
|
|
if ("QRIMG".equals(item.getParamType())) { |
|
|
if ("QRIMG".equals(item.getParamType())) { |
|
|
//渲染Qr图片
|
|
|
//渲染Qr图片
|
|
|
if(!value.isEmpty() && !value.isBlank()) { |
|
|
if(!value.isEmpty() && !value.isBlank()) { |
|
|
try { |
|
|
try { |
|
|
JSONObject jsonObject = JSONObject.parseObject(Optional.ofNullable(item.getParamDesc()).orElse("{\"width\":\"172\",\"height\":\"172\",\"type\":\"png\"}")); |
|
|
// JSONObject jsonObject = JSONObject.parseObject(Optional.ofNullable(item.getParamDesc()).orElse("{\"width\":\"172\",\"height\":\"172\",\"type\":\"png\"}"));
|
|
|
int width = 172; |
|
|
// int width = 172;
|
|
|
int height = 172; |
|
|
// int height = 172;
|
|
|
String type = "png"; |
|
|
// String type = "png";
|
|
|
if (null != jsonObject) { |
|
|
// if (null != jsonObject) {
|
|
|
width = Integer.valueOf(Optional.ofNullable(jsonObject.getString("width")).orElse("172")); |
|
|
// width = Integer.valueOf(Optional.ofNullable(jsonObject.getString("width")).orElse("172"));
|
|
|
height = Integer.valueOf(Optional.ofNullable(jsonObject.getString("height")).orElse("172")); |
|
|
// height = Integer.valueOf(Optional.ofNullable(jsonObject.getString("height")).orElse("172"));
|
|
|
type = Optional.ofNullable(jsonObject.getString("type")).orElse("png"); |
|
|
// type = Optional.ofNullable(jsonObject.getString("type")).orElse("png");
|
|
|
} |
|
|
// }
|
|
|
BufferedImage bufferedImage = qrCodeService.generateQRCode(value, width, height); |
|
|
BufferedImage bufferedImage = qrCodeService.generateQRCode(value, (int)rtl.getWidth(), (int)rtl.getHeight()); |
|
|
com.itextpdf.layout.element.Image image = getImage(field, bufferedImage, rtl); |
|
|
byte[] imgBytes = qrCodeService.getImgBuffer("png", bufferedImage); |
|
|
|
|
|
com.itextpdf.layout.element.Image image =new com.itextpdf.layout.element.Image(ImageDataFactory.create(imgBytes));//getImage(field, bufferedImage, rtl);
|
|
|
image.setFixedPosition(rtl.getX(), rtl.getY(), rtl.getWidth()); // 设置图片固定位置
|
|
|
image.setFixedPosition(rtl.getX(), rtl.getY(), rtl.getWidth()); // 设置图片固定位置
|
|
|
document.add(image); |
|
|
document.add(image); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
@ -201,19 +204,20 @@ public class PdfModelUitl { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
///*pdf 模版图片压缩处理*/
|
|
|
///*pdf 模版图片压缩处理*/
|
|
|
private com.itextpdf.layout.element.Image getImage(PdfFormField formField, BufferedImage bufferedImage,Rectangle rtl) throws IOException { |
|
|
private com.itextpdf.layout.element.Image getImage( BufferedImage bufferedImage,Rectangle rtl) throws IOException { |
|
|
byte[] imgBytes = qrCodeService.getImgBuffer("jpeg", bufferedImage); |
|
|
byte[] imgBytes = qrCodeService.getImgBuffer("png", bufferedImage); |
|
|
if (Float.compare(bufferedImage.getWidth(), rtl.getWidth()) <= 0 && Float.compare(bufferedImage.getHeight(), rtl.getHeight()) <= 0) {// 不处理
|
|
|
if (Float.compare(bufferedImage.getWidth(), rtl.getWidth()) <= 0 && Float.compare(bufferedImage.getHeight(), rtl.getHeight()) <= 0) {// 不处理
|
|
|
return new com.itextpdf.layout.element.Image(ImageDataFactory.create(imgBytes)); |
|
|
return new com.itextpdf.layout.element.Image(ImageDataFactory.create(imgBytes)); |
|
|
} else { |
|
|
} else { |
|
|
// 压缩图片。计算得到图片放缩的最大比例
|
|
|
// 压缩图片。计算得到图片放缩的最大比例
|
|
|
float scale = Math.max(bufferedImage.getWidth() / rtl.getWidth(), bufferedImage.getHeight() / rtl.getHeight()); |
|
|
float scale = Math.min(rtl.getWidth()/bufferedImage.getWidth() , rtl.getHeight() / bufferedImage.getHeight() ); |
|
|
// 压缩图片
|
|
|
// 压缩图片
|
|
|
Image scale1 = ImgUtil.scale(ImgUtil.toImage(imgBytes), scale); |
|
|
Image scale1 = ImgUtil.scale(ImgUtil.toImage(imgBytes), scale); |
|
|
return new com.itextpdf.layout.element.Image(ImageDataFactory.create(ImgUtil.toBytes(scale1, ImgUtil.IMAGE_TYPE_PNG))); |
|
|
return new com.itextpdf.layout.element.Image(ImageDataFactory.create(ImgUtil.toBytes(scale1, ImgUtil.IMAGE_TYPE_PNG))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 根据表单域关键字查找当前关键字所在页对象(PdfPage) |
|
|
* 根据表单域关键字查找当前关键字所在页对象(PdfPage) |
|
|
* |
|
|
* |
|
|