条形码、二维码放到pdf文件固定位置
package com.test; import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase; import com.spire.pdf.graphics.*; import com.spire.pdf.PdfPageSize; import com.spire.pdf.graphics.layer.PdfLayer; import java.awt.*; import java.awt.geom.Point2D; public class TuCeng { public static void main(String[] args) { PdfDocument pdf = new PdfDocument();
String namess=accessorySaveName1;
String wjjs=formatter.format(date).substring(0, 6);
String paths=ServletActionContext.getServletContext().getRealPath("/upload/govdocumentmanager/");
//加载PDF源文件
pdf.loadFromFile(paths+"/"+wjjs+"/"+namess);
//doc.loadFromFile("data/Sample.pdf");
//获取文档的第一页
PdfPageBase page = pdf.getPages().get(0);
//添加图片
drawImageMethod(paths,wjjs,txmname,page);
pdf.saveToFile(paths+"/"+wjjs+"/"+namess);
pdf.close(); } private static void drawImageMethod(String paths,String wjjs,String txmname,PdfPageBase page) {
PdfImage image = PdfImage.fromFile(paths+"/"+wjjs+"/"+txmname+".jpg");
//定义图片的长和宽的缩放倍数
float width =200;
float height =100;
//放置图片的位置
page.getCanvas().drawImage(image, 205,690, width, height);
} }
需要jar包Spire.Pdf.jar
链接: https://pan.baidu.com/s/1Qfsdcp38kDNhd6GF6IMt0Q 提取码: ipe2 复制这段内容后打开百度网盘手机App,操作更方便哦
最终预览效果:
参考链接:https://blog.csdn.net/cunxiedian8614/article/details/105689339?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160557452919195264760990%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=160557452919195264760990&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v28-5-105689339.pc_first_rank_v2_rank_v28&utm_term=java%E4%B8%ADpdf%E4%B8%8A%E6%94%BE%E5%9B%BE%E5%B1%82%E5%8F%AF%E4%BB%A5%E5%90%97&spm=1018.2118.3001.4449
https://jingyan.baidu.com/article/d45ad14868a14769552b80ac.html