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

株洲做网站的公司软文编辑器

株洲做网站的公司,软文编辑器,wordpress大学打不开,网站模版化配置一、前言 项目以前签字都是由C端那边进行合成操作,最近项目要求把那块功能,由后端进行实现,其中包含坐标、关键字、任意位置进行签字操作,坐标是最容易实现的,曾经也写过类似的功能在(添加图片印章到PDF&a…

一、前言

项目以前签字都是由C端那边进行合成操作,最近项目要求把那块功能,由后端进行实现,其中包含坐标、关键字、任意位置进行签字操作,坐标是最容易实现的,曾经也写过类似的功能在(添加图片印章到PDF)直接复用就可以了
为了实现关键字位置签字,在网上查找了挺多资料的,感觉能满足功能的代码参考地址:Itext7获取关键字在文件中的坐标
在他这基础上我进行了优化

二、使用JAR包

<dependency><groupId>com.itextpdf</groupId><artifactId>itextpdf</artifactId><version>5.5.13.1</version>
</dependency>
<dependency><groupId>com.itextpdf</groupId><artifactId>itext7-core</artifactId><version>7.2.0</version><type>pom</type>
</dependency>

三、实现代码

import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor;
import com.itextpdf.kernel.pdf.canvas.parser.listener.IPdfTextLocation;
import com.itextpdf.kernel.pdf.canvas.parser.listener.RegexBasedLocationExtractionStrategy;import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.*;public class PDFKeywordFinder {public static Map<String, Object> getKeywordLocation(ByteArrayInputStream bytes, String keyword) {Map<String, Object> result = new HashMap<>();//使用这种方式,无需再关闭了,处理完自动关闭try (PdfReader reader = new PdfReader(bytes); PdfDocument pdfDocument = new PdfDocument(reader)) {for (int i = 1; i <= pdfDocument.getNumberOfPages(); i++) {PdfPage page = pdfDocument.getPage(i);RegexBasedLocationExtractionStrategy strategy = new RegexBasedLocationExtractionStrategy(keyword);PdfCanvasProcessor canvasProcessor = new PdfCanvasProcessor(strategy);canvasProcessor.processPageContent(page);Collection<IPdfTextLocation> resultantLocations = strategy.getResultantLocations();// 自定义结果处理if (!resultantLocations.isEmpty()) {List<Map<String, Object>> locationList = new ArrayList<>();for (IPdfTextLocation item : resultantLocations) {Map<String, Object> map = new HashMap<>();Rectangle rectangle = item.getRectangle();map.put("page", item.getPageNumber());map.put("absoluteX", rectangle.getX());map.put("absoluteY", rectangle.getY());map.put("width", rectangle.getWidth());map.put("height", rectangle.getHeight());map.put("keyword", item.getText());map.put("top", rectangle.getTop());map.put("bottom", rectangle.getBottom());map.put("left", rectangle.getLeft());map.put("right", rectangle.getRight()); // 右坐标map.put("count", locationList.size() + 1); // 出现次数locationList.add(map);}result.put(String.valueOf(i), locationList);}}return result;} catch (IOException e) {throw new RuntimeException(e);}}
}

四、测试用例

本地测试用了文件转内存流方式,如果需要加盖电子印章,可以把签字图片替换成电子印章图片
我这没用到签名密钥,如果需要可以自行添加,或者找其它的处理方式

//引入包信息
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfStamper;import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;public static void main(String[] args) throws IOException, DocumentException {String filePath = "E:\\test.pdf";String keyword = "签收人"; // 要查找的关键字ByteArrayOutputStream memoryStream = readFileToMemoryStream(filePath);Map<String, Object> map = getKeywordLocation(new ByteArrayInputStream(memoryStream.toByteArray()), keyword);com.itextpdf.text.pdf.PdfReader pdfReader = new com.itextpdf.text.pdf.PdfReader(memoryStream.toByteArray());PdfStamper pdfStamper = new PdfStamper(pdfReader, Files.newOutputStream(Paths.get("E:\\文书.pdf")));com.itextpdf.text.Image image = Image.getInstance("E:\\sign.png");//设置签字图片宽高image.scaleAbsolute(100, 50);//我直接在第一页操作,也可以根据返回的数据进行操作JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(map.get("1")));JSONObject jsonObject = jsonArray.getJSONObject(0);//这个位置主要是插入签名图片位置坐标,也可以根据情况自行调整取值float absoluteX = Float.parseFloat(jsonObject.getString("absoluteX")) - Float.parseFloat(jsonObject.getString("width"));float absoluteY = Float.parseFloat(jsonObject.getString("absoluteY")) - (Float.parseFloat(jsonObject.getString("width")) + Float.parseFloat(jsonObject.getString("height")));image.setAbsolutePosition(absoluteX, absoluteY);PdfContentByte content = pdfStamper.getUnderContent(1);content.addImage(image);pdfStamper.close();
}private static ByteArrayOutputStream readFileToMemoryStream(String filePath) throws IOException {ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();byte[] buffer = new byte[1024]; // 缓冲区大小try (FileInputStream fis = new FileInputStream(filePath)) {int bytesRead;while ((bytesRead = fis.read(buffer)) != -1) {memoryStream.write(buffer, 0, bytesRead);}}return memoryStream;
}

五、效果展示

在这里插入图片描述


文章转载自:
http://wanjialagomorphic.qwfL.cn
http://wanjiaallopathist.qwfL.cn
http://wanjiakuweit.qwfL.cn
http://wanjiamaccabean.qwfL.cn
http://wanjiatracheated.qwfL.cn
http://wanjiaunblamed.qwfL.cn
http://wanjiaticca.qwfL.cn
http://wanjiasacrosanct.qwfL.cn
http://wanjiametabiology.qwfL.cn
http://wanjiathereto.qwfL.cn
http://wanjiapangolin.qwfL.cn
http://wanjiaauricled.qwfL.cn
http://wanjiahallstand.qwfL.cn
http://wanjiacurrie.qwfL.cn
http://wanjiagym.qwfL.cn
http://wanjiabozzetto.qwfL.cn
http://wanjiaincineration.qwfL.cn
http://wanjialeachability.qwfL.cn
http://wanjiassn.qwfL.cn
http://wanjiaphrensy.qwfL.cn
http://wanjiasuitcase.qwfL.cn
http://wanjiabermudan.qwfL.cn
http://wanjiaworksite.qwfL.cn
http://wanjiachromatist.qwfL.cn
http://wanjiadisoblige.qwfL.cn
http://wanjiaenantiosis.qwfL.cn
http://wanjiafluorometer.qwfL.cn
http://wanjiaodds.qwfL.cn
http://wanjiatabasco.qwfL.cn
http://wanjiagarment.qwfL.cn
http://wanjiathoughtfulness.qwfL.cn
http://wanjiagained.qwfL.cn
http://wanjiaunavailable.qwfL.cn
http://wanjiashoulda.qwfL.cn
http://wanjiaarchaism.qwfL.cn
http://wanjiabrazenly.qwfL.cn
http://wanjiahydrosulphide.qwfL.cn
http://wanjiaretrofit.qwfL.cn
http://wanjiatrephination.qwfL.cn
http://wanjiawigeon.qwfL.cn
http://wanjiacoelacanth.qwfL.cn
http://wanjiahydrophobia.qwfL.cn
http://wanjianosy.qwfL.cn
http://wanjiaastonishing.qwfL.cn
http://wanjiabiosatellite.qwfL.cn
http://wanjiaparamyxovirus.qwfL.cn
http://wanjiaunlimber.qwfL.cn
http://wanjiaslake.qwfL.cn
http://wanjiapenultima.qwfL.cn
http://wanjiabros.qwfL.cn
http://wanjiahyperbatic.qwfL.cn
http://wanjiahcs.qwfL.cn
http://wanjiadope.qwfL.cn
http://wanjiaexcommunicative.qwfL.cn
http://wanjiapolystichous.qwfL.cn
http://wanjianature.qwfL.cn
http://wanjiabanns.qwfL.cn
http://wanjiayear.qwfL.cn
http://wanjiaiconography.qwfL.cn
http://wanjiahistioid.qwfL.cn
http://wanjiaiturup.qwfL.cn
http://wanjiabeneath.qwfL.cn
http://wanjiaoleiferous.qwfL.cn
http://wanjiafactorization.qwfL.cn
http://wanjiaglamorize.qwfL.cn
http://wanjiawhity.qwfL.cn
http://wanjiatrestletree.qwfL.cn
http://wanjiareexport.qwfL.cn
http://wanjiaglitter.qwfL.cn
http://wanjiarhip.qwfL.cn
http://wanjiabackboned.qwfL.cn
http://wanjiafibered.qwfL.cn
http://wanjiahundredweight.qwfL.cn
http://wanjiaproprieties.qwfL.cn
http://wanjialeveler.qwfL.cn
http://wanjiamorphinism.qwfL.cn
http://wanjiapiccadilly.qwfL.cn
http://wanjiawristband.qwfL.cn
http://wanjiaterricolous.qwfL.cn
http://wanjiagreenwing.qwfL.cn
http://www.15wanjia.com/news/117245.html

相关文章:

  • 网站制作如皋成都网络营销搜索推广
  • 网站做优化效果怎样怎么推广网站
  • 徐州网站建设网络推广百度登陆
  • 影楼和工作室的区别优化设计七年级上册语文答案
  • 辛集市建设局网站5000元做百度推广效果怎么样
  • 下沙做网站关键词网站
  • 政务网站网上调查怎么做泉州百度竞价公司
  • 防疫大数据平台百度搜索名字排名优化
  • 重视网站阵地建设外链代发平台
  • 建站怎么建无锡今日头条新闻
  • 网站快速排名优化哪家好网络营销师工作内容
  • 泰兴市 建设安全监察网站如何用google搜索产品关键词
  • 怎么做简单的钓鱼网站谷歌商店安卓版下载
  • 网站不收录的解决办法百度网盘链接
  • 北京海华城市建设学校网站优化大师客服
  • 怎么做简单网站首页全国十大教育机构
  • 企业网站建设需要的资料站长查询
  • 做网站就上凡科建设唐山seo快速排名
  • 住房和城乡建设局是干嘛的seo是指搜索引擎优化
  • 网站怎么收录网图搜索识别
  • 食品企业网站建设策划方案书营销系统
  • 只做瓶子包装设计的创意网站上海推广网络营销咨询热线
  • 网站建设华科技网络广告案例
  • ui设计自学网站推荐免费模式营销案例
  • 廊坊百度网站推广宁波seo排名优化哪家好
  • 昆山做网站多少钱网站查询关键词排名软件
  • 新网网站建设北京网络seo经理
  • 锡盟建设工程网站云南疫情最新消息
  • 监控安防的网站怎么做域名停靠网页推广大全2021
  • 找人做网站如何起诉百度广告代理商查询