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

商城网站建设经验想做推广哪个平台好

商城网站建设经验,想做推广哪个平台好,创可贴网站怎么做图片,wordpress全站背景kkFileView二开之Pdf转图片接口 1 kkFileView源码下载及编译2 Pdf转图片接口2.1 背景2.2 分析2.2 接口开发2.2.1 编写Pdf转图片方法2.2.2 编写转换接口 2.3 接口测试2.3.1 Pdf文件准备2.3.2 pdf2Image 3 部署 1 kkFileView源码下载及编译 前文 【kkFileView二开之源码编译及部…

kkFileView二开之Pdf转图片接口

  • 1 kkFileView源码下载及编译
  • 2 Pdf转图片接口
    • 2.1 背景
    • 2.2 分析
    • 2.2 接口开发
      • 2.2.1 编写Pdf转图片方法
      • 2.2.2 编写转换接口
    • 2.3 接口测试
      • 2.3.1 Pdf文件准备
      • 2.3.2 pdf2Image
  • 3 部署

1 kkFileView源码下载及编译

前文 【kkFileView二开之源码编译及部署】 已完成了kkFileView源码二开的基础准备。

2 Pdf转图片接口

2.1 背景

在实际工作过程中,存在Pdf转图片的需求,比如人员证书,通过pdf模板填充后,生成对应的图片。

2.2 分析

kkFiewView 针对pdf在线预览会有两种方式,一种是转换为图片进行预览,一种是保留原始pdf格式进行预览,此处可以调用kkfiewView底层中pdf转图片预览的方式,实现对应的接口

2.2 接口开发

2.2.1 编写Pdf转图片方法

在cn.keking.service.FileHandlerService.java 中,新增转换方法:

/*** pdf转换为图片* @param pdfFilePath* @param fileAttribute* @return* @throws Exception*/public List<String> pdf2jpgBase64(String pdfFilePath,FileAttribute fileAttribute) throws Exception {String filePassword = fileAttribute.getFilePassword();PDDocument doc = null;List<String> imageFile = new ArrayList<>();try {File pdfFile = new File(pdfFilePath);if (!pdfFile.exists()) {return null;}doc = Loader.loadPDF(pdfFile, filePassword);doc.setResourceCache(new NotResourceCache());int pageCount = doc.getNumberOfPages();PDFRenderer pdfRenderer = new PDFRenderer(doc);for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getPdf2JpgDpi(), ImageType.RGB);imageFile.add(ImgUtil.toBase64DataUri(image,"jpg"));}} catch (IOException e) {logger.error("Convert pdf to jpg exception, pdfFilePath:{}", pdfFilePath, e);throw new Exception(e);} finally {if (doc != null) {   //关闭doc.close();}}return imageFile;}

2.2.2 编写转换接口

在cn.keking.web.controller包下,新增ConvertController.java 文件

package cn.keking.web.controller;import cn.hutool.core.io.FileUtil;
import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute;
import cn.keking.model.FileType;
import cn.keking.service.FileHandlerService;
import cn.keking.service.OfficeToPdfService;
import cn.keking.utils.KkFileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;/*** 文件转换接口*/
@Controller
public class ConvertController {private final String fileDir = ConfigConstants.getFileDir();//临时目录private final String tempPath = "temp" + File.separator;@Autowiredprivate OfficeToPdfService officeToPdfService;@Autowiredprivate FileHandlerService fileHandlerService;private static final String FILE_DIR = ConfigConstants.getFileDir();/*** pdf转换为图片* @param req* @param rep* @param file*/@PostMapping("/pdf2Image")@ResponseBodypublic Map<String,Object> pdf2Image(HttpServletRequest req, HttpServletResponse rep, @RequestParam("file") MultipartFile file) {Map<String,Object> result = new HashMap<>();FileAttribute fileAttribute = new FileAttribute();String fullFileName = file.getOriginalFilename();fileAttribute.setType(FileType.typeFromFileName(fullFileName));fileAttribute.setName(fullFileName);fileAttribute.setSuffix(KkFileUtils.suffixFromFileName(fullFileName));try {String pdfName = fullFileName.substring(0, fullFileName.lastIndexOf(".") + 1) + "pdf";String outFilePath = FILE_DIR + pdfName;FileUtil.writeFromStream(file.getInputStream(),outFilePath);List<String> imageUrls = fileHandlerService.pdf2jpgBase64(outFilePath, fileAttribute);result.put("code",200);result.put("msg","转换成功");result.put("data",imageUrls);}catch (Exception e){e.printStackTrace();result.put("code",500);result.put("msg","pdf转换图片异常:"+e.getMessage());}return result;}
}

2.3 接口测试

2.3.1 Pdf文件准备

在这里插入图片描述

2.3.2 pdf2Image

使用Apifox新建接口,按如下方式配置,并点击发送
注意:通过源码分析可知,在Pdf进行预览过程中,预览速度会随着pdf的大小不同而不同,pdf越大,则接口速度越慢,因为是一次性将对应的pdf全部转换后返回至前端的。
在这里插入图片描述
结果格式化效果(pdf文件有85页,所以data中有85条数据)
在这里插入图片描述
按如下方式,将生成的每一条数据写入到img标签中

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head><meta charset="utf-8" /><title>New Document</title>
</head>
<body><img src="data标签中的每一行数据" alt="" />
</body>
</html>

在浏览器中打开编写的html文件,如效果图所示,即为转换后的base64图片
在这里插入图片描述

3 部署

可参考 【kkFileView二开之源码编译及部署】 文档中,【部署】目录下的方式,根据部署的平台选择合适的方式进行部署。

http://www.dtcms.com/wzjs/456095.html

相关文章:

  • seo兼职论坛seo关键词推广价格
  • 阿里企业邮箱价格廊坊百度seo公司
  • vue做的网站多么手机版百度一下
  • 关于军队建设网站怎么做市场营销和推广
  • 做电影免费ppt模板下载网站google官方版下载
  • 制作一个论坛网站多少钱网络推广营销策划方案
  • 网站开发发送短信夫唯seo怎么样
  • 微网站技术seo排名专业公司
  • 网站的空间与域名北京优化seo
  • 西安响应式网站建设哪家强网站后端开发
  • 注册网站的流程朋友圈广告怎么投放
  • 尤溪建设局网站怎么在网上做广告宣传
  • 免费的网址域名seo全网营销
  • 做网站标题图片大小百度搜索的优势
  • 学产品设计专业后悔了广州网站制作实力乐云seo
  • 在linux系统上用什么做网站怎么办网站平台
  • 网络工程师中级职称考试内容网站seo最新优化方法
  • 做虾苗网站有哪些流程新闻20条摘抄大全
  • 兴义市住房和城乡建设网站月销售宣传网站有哪些
  • saas建站平台源码杭州优化seo公司
  • 综合型网站建设北京建站
  • 企业邮箱给我一个深圳专门做seo的公司
  • 群晖 做网站 Java百度视频下载
  • 平邑做网站推广公司简介
  • 做游戏代练的网站星链友店
  • 做网站首页图的规格品牌营销策略
  • 成都高端网站制作安卓优化软件
  • 设计网站如何融入非关系数据库住房和城乡建设部
  • 单页网站开发费用什么叫软文推广
  • asp企业网站源码下载惠州网站排名提升