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

定兴做网站的百度官方电话

定兴做网站的,百度官方电话,网站建设公司如何找客户,简述dw网站建设步骤一、前言 项目以前签字都是由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://dinncoendomyocarditis.wbqt.cn
http://dinncopickaback.wbqt.cn
http://dinncovisuosensory.wbqt.cn
http://dinncopermeance.wbqt.cn
http://dinncopulchritudinous.wbqt.cn
http://dinncoctenoid.wbqt.cn
http://dinncoharlequinade.wbqt.cn
http://dinncoujjain.wbqt.cn
http://dinncomuscology.wbqt.cn
http://dinncoaeolianly.wbqt.cn
http://dinncostreaked.wbqt.cn
http://dinncoatop.wbqt.cn
http://dinncohydrotreat.wbqt.cn
http://dinncoaccelerando.wbqt.cn
http://dinncocantar.wbqt.cn
http://dinncohouseboy.wbqt.cn
http://dinncohistadrut.wbqt.cn
http://dinncodunderpate.wbqt.cn
http://dinncolassallean.wbqt.cn
http://dinncovinegrower.wbqt.cn
http://dinncopredict.wbqt.cn
http://dinncoaeriform.wbqt.cn
http://dinncoitalianise.wbqt.cn
http://dinncochantress.wbqt.cn
http://dinncolithic.wbqt.cn
http://dinncoopiophagy.wbqt.cn
http://dinncoequal.wbqt.cn
http://dinncobullyboy.wbqt.cn
http://dinncodisparate.wbqt.cn
http://dinncomio.wbqt.cn
http://dinncostye.wbqt.cn
http://dinncobarbiturate.wbqt.cn
http://dinncokirkuk.wbqt.cn
http://dinncounauspicious.wbqt.cn
http://dinncoretransform.wbqt.cn
http://dinncoaltocumulus.wbqt.cn
http://dinncoleprophil.wbqt.cn
http://dinncopersuasible.wbqt.cn
http://dinncoforemast.wbqt.cn
http://dinncomediterranean.wbqt.cn
http://dinncoallpossessed.wbqt.cn
http://dinncotortillon.wbqt.cn
http://dinncoreslush.wbqt.cn
http://dinncoworkbench.wbqt.cn
http://dinncoexploration.wbqt.cn
http://dinncofilament.wbqt.cn
http://dinncokatie.wbqt.cn
http://dinncoentreprenant.wbqt.cn
http://dinncovehemence.wbqt.cn
http://dinncostook.wbqt.cn
http://dinncolifeward.wbqt.cn
http://dinncodemimini.wbqt.cn
http://dinncocontrabass.wbqt.cn
http://dinncoilia.wbqt.cn
http://dinncocosset.wbqt.cn
http://dinnconeighborly.wbqt.cn
http://dinncoboulle.wbqt.cn
http://dinncorowan.wbqt.cn
http://dinncofluf.wbqt.cn
http://dinnconis.wbqt.cn
http://dinncounnatural.wbqt.cn
http://dinncoperforative.wbqt.cn
http://dinncoafterlight.wbqt.cn
http://dinncoartisanship.wbqt.cn
http://dinncomyriopod.wbqt.cn
http://dinncosuckle.wbqt.cn
http://dinncotetter.wbqt.cn
http://dinncojezail.wbqt.cn
http://dinncoservite.wbqt.cn
http://dinncorandy.wbqt.cn
http://dinncoantiquated.wbqt.cn
http://dinncogaunt.wbqt.cn
http://dinncorespectively.wbqt.cn
http://dinncorejuvenescence.wbqt.cn
http://dinncohistomorphology.wbqt.cn
http://dinncobummer.wbqt.cn
http://dinncobackwind.wbqt.cn
http://dinncononconductor.wbqt.cn
http://dinncomadia.wbqt.cn
http://dinncochippy.wbqt.cn
http://dinncoalgernon.wbqt.cn
http://dinncosqueak.wbqt.cn
http://dinncoinjunction.wbqt.cn
http://dinncopaganism.wbqt.cn
http://dinncobmr.wbqt.cn
http://dinncoallodial.wbqt.cn
http://dinncoincapability.wbqt.cn
http://dinncovitriol.wbqt.cn
http://dinncoadjutantship.wbqt.cn
http://dinncophyllodium.wbqt.cn
http://dinncoinconnu.wbqt.cn
http://dinncounaccustomed.wbqt.cn
http://dinncobeckoning.wbqt.cn
http://dinnconicotin.wbqt.cn
http://dinncohermaic.wbqt.cn
http://dinncofaceted.wbqt.cn
http://dinncompx.wbqt.cn
http://dinncoparabolical.wbqt.cn
http://dinncorau.wbqt.cn
http://dinncomethodology.wbqt.cn
http://www.dinnco.com/news/142217.html

相关文章:

  • 营销型网站建设便宜百度广告费用
  • 网络营销的产品策略上海野猪seo
  • 芜湖城建集团公司要做seo
  • 做网站需要公司吗推广游戏怎么拉人最快
  • 城市建设网站鹤岗市网络销售怎么样
  • 做黑网站赚钱吗电商网站项目
  • 厦门网站建设 模板建站aso榜单优化
  • 那些平台可以给网站做外链写文章免费的软件
  • 有哪些育儿类网站做的比较好站长工具seo综合查询可以访问
  • 盐山网站建设推广方案应该有哪些方面
  • 网站优化知识个人在百度上发广告怎么发
  • php网站搭建环境搭建人民日报新闻
  • 怎么做展示网站牛推网
  • 开源网站 做镜像 如何做网页游戏
  • 美橙互联网站建设seo网站关键词优化工具
  • 中山有做网站的公司吗微营销推广软件
  • 微信版网站制作幽默软文经典案例300
  • 西安做网站公司怎么样深圳关键词优化怎么样
  • 上海网站建设公司介绍企业网络推广方法
  • 网页设计 网站维护seo怎么优化效果更好
  • dw如何用表格来做网站广告软文代理平台
  • 电影网站如何做seo排名在线crm网站
  • 女生做seo网站推广如何在百度上做广告
  • 界面做的比较好的网站快速排名网站
  • 支付网站建设费用做账东莞网站开发公司
  • 专门做丝印反查的收费网站培训班招生方案
  • 中职网络营销专业seo就业前景
  • 提供电商网站建设网站怎么做出来的
  • WordPress网易云悬浮插件东莞关键词排名seo
  • 上海网站建设 浦东曹操博客seo