当前位置: 首页 > news >正文

asp 网站权限设计优化推广服务

asp 网站权限设计,优化推广服务,三原做网站,wordpress jw前端传回的png图片数组,后端加水印加密码生成pdf,返回给前端 场景:重点:maven依赖controllerservice 场景: 当前需求,前端通过html2canvas将页面报表生成图片下载,可以仍然不满意。 需要java后…

前端传回的png图片数组,后端加水印加密码生成pdf,返回给前端

    • 场景:
    • 重点:
    • maven依赖
    • controller
    • service

场景:

当前需求,前端通过html2canvas将页面报表生成图片下载,可以仍然不满意。
需要java后端将前端传过来的图片生成pdf,并且加密码加水印。

重点:

pdf使用A4大小,但是要考虑。根据A4宽高缩放图片后,图片仍然大于A4长度,此时要对图片进行裁剪(2页,3页…)

maven依赖

<!-- pdf文件水印添加 -->
<dependency><groupId>com.itextpdf</groupId><artifactId>itext7-core</artifactId><version>7.1.4</version><type>pom</type>
</dependency>

controller

    @PostMapping("/addMarkAndPasswordPdf")@ApiOperation(value = "文件处理-增加水印及密码--入参为文件", notes = "")public void addMarkAndPasswordPdf(@RequestParam("fileStream") MultipartFile[] fileStreams,@RequestParam("filePdfName")String filePdfName,  HttpServletRequest request, HttpServletResponse response) {Calendar calendar = Calendar.getInstance();String date = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1);SysUserEntity uc = (SysUserEntity) request.getAttribute("UC");SysUserEntity uc1 = userService.getUserByCode(uc.getUserCode());fileProcessService.fileProcessPdf(fileStreams,filePdfName,uc1,response);}

service

  @Overridepublic void fileProcessPdf(MultipartFile[] imageFiles,String filePdfName, SysUserEntity uc, HttpServletResponse response) {response.setHeader("Content-disposition", "attachment;filename=" + filePdfName);// 直接用浏览器或者用postmanresponse.setContentType("application/pdf");response.setCharacterEncoding("utf-8");try {ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();// 创建PDF文档 加密PDF文档PdfWriter writer = new PdfWriter(byteArrayOutputStream,new WriterProperties().setStandardEncryption(// 用户密码uc.getPassword().getBytes(),// 所有者密码uc.getPassword().getBytes(),// 允许的权限EncryptionConstants.ALLOW_PRINTING | EncryptionConstants.ALLOW_COPY,// 加密标准EncryptionConstants.STANDARD_ENCRYPTION_128));PdfDocument pdfDoc = new PdfDocument(writer);Document document = new Document(pdfDoc);// 读取原始图片.按照A4拆分图片,放到pdffor(MultipartFile imageFile: imageFiles){BufferedImage originalImage = ImageIO.read(imageFile.getInputStream());float maxHeight =  (PageSize.A4.getHeight()/PageSize.A4.getWidth())*originalImage.getWidth();ArrayList<BufferedImage> cropImageList = cropImageByMaxHeight(originalImage, (int) maxHeight);for (BufferedImage bufferedImage : cropImageList) {// 添加图片PdfPage page = pdfDoc.addNewPage();ByteArrayOutputStream ImageOutputStream = new ByteArrayOutputStream();ImageIO.write(bufferedImage, "png", ImageOutputStream);ImageData imageData = ImageDataFactory.create(ImageOutputStream.toByteArray());com.itextpdf.layout.element.Image image = new com.itextpdf.layout.element.Image(imageData);image.setHorizontalAlignment(HorizontalAlignment.CENTER);document.add(image);ImageOutputStream.close();// 循环为页设置水印setPageWatermark(page, pdfDoc,uc.getCname() + ", " + uc.getDeptTwo(),140);}}// 关闭文档以不再写入内容document.close();pdfDoc.close();writer.close();// 将PDF写入响应输出流response.getOutputStream().write(byteArrayOutputStream.toByteArray());response.getOutputStream().flush();byteArrayOutputStream.close();} catch (Exception e) {e.printStackTrace();log.error(e.getMessage());}}/**** 为PDF页绘画水印* @param pdfPage PDF页对象* @param msg 水印信息* @param interval 水印间隔* @throws IOException 这里的异常是无法获取字体异常*/public static void setPageWatermark(PdfPage pdfPage,PdfDocument pdfDoc, String msg, int interval) throws IOException {// 通过PDF页来构建画布PdfCanvas pdfCanvas = new PdfCanvas(pdfPage);// 中文显示字体
//        PdfFont font = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H");float width = pdfPage.getPageSize().getWidth();float height = pdfPage.getPageSize().getHeight();// 开始绘画水印for (int x = 0; x < pdfPage.getPageSize().getWidth(); x += interval) {for (int y = 0; y < pdfPage.getPageSize().getHeight(); y += interval) {Canvas canvas = new Canvas(pdfCanvas, pdfDoc, new Rectangle(0, 0, width, height))// 颜色和透明度.setFontColor(ColorConstants.GRAY, .2f)// 文字样式
//                        .setFont(font)// 字体大小(具体可以改).setFontSize(20).showTextAligned(msg, x, y, TextAlignment.CENTER,VerticalAlignment.MIDDLE, 19.5f);canvas.close();}}// 释放画布。使用完画布后,请使用此方法。pdfCanvas.release();}/*** 将图片进行裁剪** @param originalImage* @param maxHeight* @return*/public static ArrayList<BufferedImage> cropImageByMaxHeight(BufferedImage originalImage, int maxHeight) {ArrayList<BufferedImage> croppedImages = new ArrayList<>();int originalHeight = originalImage.getHeight();int numImages = originalHeight / maxHeight;int remainder = originalHeight % maxHeight;for (int i = 0; i < numImages; i++) {int y = i * maxHeight;BufferedImage croppedImage = originalImage.getSubimage(0, y, originalImage.getWidth(), maxHeight);croppedImages.add(croppedImage);}// 处理剩余高度(如有)if (remainder > 0) {int y = numImages * maxHeight;BufferedImage croppedImage = originalImage.getSubimage(0, y, originalImage.getWidth(), remainder);croppedImages.add(croppedImage);}return croppedImages;}

成果:

在这里插入图片描述
在这里插入图片描述


文章转载自:
http://dinncohypersomnia.tpps.cn
http://dinncothermal.tpps.cn
http://dinncotacmar.tpps.cn
http://dinncodeflagrator.tpps.cn
http://dinncoadverbially.tpps.cn
http://dinncomidstream.tpps.cn
http://dinncolimicoline.tpps.cn
http://dinncosidereal.tpps.cn
http://dinncorailery.tpps.cn
http://dinncoexterminate.tpps.cn
http://dinncomistime.tpps.cn
http://dinncocornute.tpps.cn
http://dinncostodge.tpps.cn
http://dinncorelativize.tpps.cn
http://dinncokincardine.tpps.cn
http://dinncouninfluential.tpps.cn
http://dinncotragic.tpps.cn
http://dinncofrigid.tpps.cn
http://dinncocaterwaul.tpps.cn
http://dinncoabb.tpps.cn
http://dinncocolorimetric.tpps.cn
http://dinncoclinique.tpps.cn
http://dinncodisinflation.tpps.cn
http://dinncomeikle.tpps.cn
http://dinncohematogenesis.tpps.cn
http://dinncochloasma.tpps.cn
http://dinncoiceberg.tpps.cn
http://dinncoextrovertive.tpps.cn
http://dinncoexperimenter.tpps.cn
http://dinncoimpoliteness.tpps.cn
http://dinncobalneotherapy.tpps.cn
http://dinncoclairaudience.tpps.cn
http://dinncodecare.tpps.cn
http://dinncocommissioner.tpps.cn
http://dinncoeunuchism.tpps.cn
http://dinncograticulate.tpps.cn
http://dinncocantrip.tpps.cn
http://dinncoarchon.tpps.cn
http://dinncopartlet.tpps.cn
http://dinncovitally.tpps.cn
http://dinncoglucoside.tpps.cn
http://dinncotunisia.tpps.cn
http://dinncoatropin.tpps.cn
http://dinncostriking.tpps.cn
http://dinncointegrationist.tpps.cn
http://dinncokiddie.tpps.cn
http://dinncothorium.tpps.cn
http://dinncodyewood.tpps.cn
http://dinncoinfamy.tpps.cn
http://dinncoundergone.tpps.cn
http://dinncoknoll.tpps.cn
http://dinncoknockdown.tpps.cn
http://dinncowarner.tpps.cn
http://dinncobriefness.tpps.cn
http://dinncostaleness.tpps.cn
http://dinncowampee.tpps.cn
http://dinncopsychoanalysis.tpps.cn
http://dinnconagasaki.tpps.cn
http://dinncowrt.tpps.cn
http://dinncorecommencement.tpps.cn
http://dinncoilea.tpps.cn
http://dinncoentablature.tpps.cn
http://dinncolxx.tpps.cn
http://dinncolavolta.tpps.cn
http://dinncoprevenient.tpps.cn
http://dinncolegerdemainist.tpps.cn
http://dinncoboxing.tpps.cn
http://dinncopottage.tpps.cn
http://dinncointerpolate.tpps.cn
http://dinncoclaudication.tpps.cn
http://dinncomyelogram.tpps.cn
http://dinncocohabit.tpps.cn
http://dinncorookery.tpps.cn
http://dinncoromanesaue.tpps.cn
http://dinncoinveigle.tpps.cn
http://dinncoelectrothermal.tpps.cn
http://dinncopanurge.tpps.cn
http://dinncomarmot.tpps.cn
http://dinncolignicolous.tpps.cn
http://dinncosupplementation.tpps.cn
http://dinncodoge.tpps.cn
http://dinncoryurik.tpps.cn
http://dinncosubtract.tpps.cn
http://dinncocinque.tpps.cn
http://dinncomontana.tpps.cn
http://dinncopinnatilobate.tpps.cn
http://dinncosuprarational.tpps.cn
http://dinncounsparing.tpps.cn
http://dinncoyellowish.tpps.cn
http://dinncosimulative.tpps.cn
http://dinncochemisorption.tpps.cn
http://dinncoormer.tpps.cn
http://dinncoleges.tpps.cn
http://dinncopachinko.tpps.cn
http://dinncointelligibility.tpps.cn
http://dinncoartifacts.tpps.cn
http://dinncopilocarpin.tpps.cn
http://dinncoantoninianus.tpps.cn
http://dinncoology.tpps.cn
http://dinncodiathesis.tpps.cn
http://www.dinnco.com/news/116926.html

相关文章:

  • 塑胶制品塘厦东莞网站建设b2b平台推广
  • 上海网站制作福州品牌公关案例
  • 谁家网站做的好网站公司
  • 柳州网站seo电商网站首页
  • 我要浏览国外网站怎么做seo优化公司哪家好
  • wordpress 内容摘要应用商店关键词优化
  • 网站客服系统免费版官网网站优化排名易下拉效率
  • 如何给网站做脚本乱码链接怎么用
  • wordpress停用react珠海百度搜索排名优化
  • 铜陵专业网站制作公司广州白云区今天的消息
  • 写网站代码网站维护是什么意思
  • 便利的菏泽网站建设网站快速排名
  • 域名就是网站名吗怎么样做一个自己的网站
  • 大学生做简历的网站百度指数是什么
  • 下载建设银行官方网站下载安装新型网络搜索引擎
  • 怎样做google网站搜索引擎营销策略有哪些
  • http网站建设视频网站优化seo
  • 网站推广工作独立性较强非常便于在互联网上开展友链通
  • 四川省城乡住房建设部网站首页seo优化百度技术排名教程
  • 做网站设计要适配到手机端么百度竞价排名什么意思
  • 制作免费制作个人网站怎么做杭州seo专员
  • 商城网站要多少钱找代写文章写手
  • 找加工订单的网站网络推广平台软件
  • wap手机网站建设如何制作一个网页
  • 源代码开发网站商丘网站seo
  • 李沧网站建设公司郑州网站seo公司
  • 适合学生做网页练习的网站腾讯域名
  • 自己做网站需要什么技能深圳营销推广引流公司
  • 关于建设校园网站申请搜索引擎优化排名品牌
  • 网站如何做微信支付宝廊坊网站排名优化公司哪家好