diff --git a/models/tag_model_001.pdf b/models/tag_model_001.pdf new file mode 100644 index 0000000..c497825 Binary files /dev/null and b/models/tag_model_001.pdf differ diff --git a/models/wuliaotest01.pdf b/models/wuliaotest01.pdf deleted file mode 100644 index 270b652..0000000 Binary files a/models/wuliaotest01.pdf and /dev/null differ diff --git a/win-print/src/main/java/com/win/print/service/QRCodeService.java b/win-print/src/main/java/com/win/print/service/QRCodeService.java index 29be04a..a65b22b 100644 --- a/win-print/src/main/java/com/win/print/service/QRCodeService.java +++ b/win-print/src/main/java/com/win/print/service/QRCodeService.java @@ -27,7 +27,7 @@ public class QRCodeService { // 设置错误纠正级别为L,表示较低的纠错能力。 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); // 设置边距为2,即二维码边缘与内容之间的距离为2个像素。 - hints.put(EncodeHintType.MARGIN, 0); + hints.put(EncodeHintType.MARGIN, 1); // 设置字符集为UTF-8,表示二维码支持UTF-8编码的字符。 hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); diff --git a/win-print/src/main/java/com/win/print/util/PdfModelUitl.java b/win-print/src/main/java/com/win/print/util/PdfModelUitl.java index d8124c9..860dfb3 100644 --- a/win-print/src/main/java/com/win/print/util/PdfModelUitl.java +++ b/win-print/src/main/java/com/win/print/util/PdfModelUitl.java @@ -77,22 +77,25 @@ public class PdfModelUitl { if(null!=field) { Rectangle rtl = field.getWidgets().get(0).getRectangle().toRectangle(); // 获取表单域的xy坐标 field.setFont(defaultFont()); - field.setFontSize(12); + if(Optional.ofNullable(field.getFontSize()).isEmpty()){ + field.setFontSize(16); + } if ("QRIMG".equals(item.getParamType())) { //渲染Qr图片 if(!value.isEmpty() && !value.isBlank()) { try { - JSONObject jsonObject = JSONObject.parseObject(Optional.ofNullable(item.getParamDesc()).orElse("{\"width\":\"172\",\"height\":\"172\",\"type\":\"png\"}")); - int width = 172; - int height = 172; - String type = "png"; - if (null != jsonObject) { - width = Integer.valueOf(Optional.ofNullable(jsonObject.getString("width")).orElse("172")); - height = Integer.valueOf(Optional.ofNullable(jsonObject.getString("height")).orElse("172")); - type = Optional.ofNullable(jsonObject.getString("type")).orElse("png"); - } - BufferedImage bufferedImage = qrCodeService.generateQRCode(value, width, height); - com.itextpdf.layout.element.Image image = getImage(field, bufferedImage, rtl); +// JSONObject jsonObject = JSONObject.parseObject(Optional.ofNullable(item.getParamDesc()).orElse("{\"width\":\"172\",\"height\":\"172\",\"type\":\"png\"}")); +// int width = 172; +// int height = 172; +// String type = "png"; +// if (null != jsonObject) { +// width = Integer.valueOf(Optional.ofNullable(jsonObject.getString("width")).orElse("172")); +// height = Integer.valueOf(Optional.ofNullable(jsonObject.getString("height")).orElse("172")); +// type = Optional.ofNullable(jsonObject.getString("type")).orElse("png"); +// } + BufferedImage bufferedImage = qrCodeService.generateQRCode(value, (int)rtl.getWidth(), (int)rtl.getHeight()); + 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()); // 设置图片固定位置 document.add(image); } catch (IOException e) { @@ -201,19 +204,20 @@ public class PdfModelUitl { } } ///*pdf 模版图片压缩处理*/ - private com.itextpdf.layout.element.Image getImage(PdfFormField formField, BufferedImage bufferedImage,Rectangle rtl) throws IOException { - byte[] imgBytes = qrCodeService.getImgBuffer("jpeg", bufferedImage); + private com.itextpdf.layout.element.Image getImage( BufferedImage bufferedImage,Rectangle rtl) throws IOException { + byte[] imgBytes = qrCodeService.getImgBuffer("png", bufferedImage); 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)); } 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); return new com.itextpdf.layout.element.Image(ImageDataFactory.create(ImgUtil.toBytes(scale1, ImgUtil.IMAGE_TYPE_PNG))); } } + /** * 根据表单域关键字查找当前关键字所在页对象(PdfPage) * diff --git a/win-print/src/main/resources/templates/print/modelmanager/add.html b/win-print/src/main/resources/templates/print/modelmanager/add.html index 165da30..ab3a174 100644 --- a/win-print/src/main/resources/templates/print/modelmanager/add.html +++ b/win-print/src/main/resources/templates/print/modelmanager/add.html @@ -44,11 +44,11 @@ -
+ diff --git a/win-print/src/main/resources/templates/print/modelmanager/edit.html b/win-print/src/main/resources/templates/print/modelmanager/edit.html index b4fb595..c2a3dd8 100644 --- a/win-print/src/main/resources/templates/print/modelmanager/edit.html +++ b/win-print/src/main/resources/templates/print/modelmanager/edit.html @@ -48,7 +48,7 @@
- +