|
@@ -13,6 +13,9 @@ import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
|
import com.google.zxing.common.BitMatrix;
|
|
|
import com.google.zxing.qrcode.QRCodeWriter;
|
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
|
|
+import com.lowagie.text.DocumentException;
|
|
|
+import com.lowagie.text.pdf.PdfReader;
|
|
|
+import com.lowagie.text.pdf.PdfStamper;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxSeaBindProofDao;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxSeaBindProofDetalService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxSeaBindProofService;
|
|
@@ -61,7 +64,7 @@ public class ZhcxSeaBindProofServiceImpl extends ServiceImpl<ZhcxSeaBindProofDao
|
|
|
throw new CustomException("参数异常,请联系管理员排查");
|
|
|
}
|
|
|
|
|
|
- // 获取模板文件
|
|
|
+ // 获取模板文件1
|
|
|
SysFileItemDo templateFile = sysFileItemService.getById("351d7b0c79034a25882415ae4332d0c3");
|
|
|
|
|
|
if (!excelUtils.GetLicense()) {
|
|
@@ -374,4 +377,35 @@ public class ZhcxSeaBindProofServiceImpl extends ServiceImpl<ZhcxSeaBindProofDao
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void previewPdf(HttpServletResponse response, String id) {
|
|
|
+ // 通过 id 获取 SysFileItemDo 对象
|
|
|
+ SysFileItemDo templateFile = sysFileItemService.getById(id);
|
|
|
+
|
|
|
+ // 获取 PDF 文件的路径
|
|
|
+ String filePath = templateFile.getFullpath();
|
|
|
+
|
|
|
+ // 设置响应头,告诉浏览器这是一个 PDF 文件,并且以预览方式显示
|
|
|
+ response.setContentType("application/pdf");
|
|
|
+ response.setHeader("Content-Disposition", "inline; filename=\"" + new File(filePath).getName() + "\"");
|
|
|
+
|
|
|
+ // 读取 PDF 文件并将其输出到响应流
|
|
|
+ try (FileInputStream pdfInputStream = new FileInputStream(filePath);
|
|
|
+ OutputStream outputStream = response.getOutputStream()) {
|
|
|
+ // 使用 iText 读取 PDF 文件
|
|
|
+ PdfReader pdfReader = new PdfReader(pdfInputStream);
|
|
|
+ PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream);
|
|
|
+
|
|
|
+ // 不做任何修改,直接将文件输出到响应流
|
|
|
+ pdfStamper.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ // 这里可以处理异常,例如返回一个错误信息
|
|
|
+ } catch (DocumentException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|