Browse Source

1、电子合同加签

master
Aug 1 week ago
parent
commit
bd1d86f3d5
3 changed files with 80 additions and 0 deletions
  1. +7
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/controller2/ContractController.java
  2. +3
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/ContractService.java
  3. +70
    -0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/ContractServiceImpl.java

+ 7
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/controller2/ContractController.java View File

@ -111,4 +111,11 @@ public class ContractController {
return contractService.image2pdf(images); return contractService.image2pdf(images);
} }
//我的服务-电子合同
@ApiOperation(value="工具-pdf加签名", notes="工具-pdf加签名")
@RequestMapping(value = "/signPdf", method = {RequestMethod.GET})
public Result<?> signPdf(String pdfPath, String imagePath, int pageNo, float positionX, float positonY, float imageWidth, float imageHeight){
return contractService.signPdf(pdfPath, imagePath, pageNo, positionX, positonY, imageWidth, imageHeight);
}
} }

+ 3
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/ContractService.java View File

@ -98,4 +98,7 @@ public interface ContractService {
//工具-图片转pdf(多个图片用;分隔) //工具-图片转pdf(多个图片用;分隔)
public Result<?> image2pdf(String images); public Result<?> image2pdf(String images);
//工具-图片转pdf(多个图片用;分隔)
public Result<?> signPdf(String pdfPath, String imagePath, int pageNo, float positionX, float positonY, float imageWidth, float imageHeight);
} }

+ 70
- 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/ContractServiceImpl.java View File

@ -375,6 +375,76 @@ public class ContractServiceImpl implements ContractService {
return Result.OK("pdf地址", pdfUrl); return Result.OK("pdf地址", pdfUrl);
} }
public Result<?> signPdf(String pdfPath, String imagePath, int pageNo, float positionX, float positonY, float imageWidth, float imageHeight){
String tempPath = System.getProperty("java.io.tmpdir") + File.separator + "resultPdf.pdf";//临时文件路径
String resultPdfPath = null;
try{
//1获得文件流对象
InputStream pdfInputStream = new URL(pdfPath).openStream();
InputStream imageInputStream = new URL(imagePath).openStream();
//2得到PDF文档对象
PDDocument document = PDDocument.load(pdfInputStream);
int pageNum = document.getNumberOfPages();
if(pageNo<0 || pageNo>pageNum){
String message = "签名页码超出范围(0~"+pageNum+"),请输入正确的签名页码,当前传入页码:"+pageNo;
return Result.OK("签名页码超出范围,输入正确的签名页码");
}
//3由Document得到Page对象
PDPage page = document.getPage(pageNo-1);//页码下标从0开始
//4通过图片路径和PDF文档对象得到图片image对象
//PDImageXObject image = PDImageXObject.createFromFile(PNG_PATH, document);
PDImageXObject image = createImageFromInputStream(document, imageInputStream);
//5创建pageStream对象
PDPageContentStream pageStream = new PDPageContentStream(document, page,PDPageContentStream.AppendMode.APPEND,false,false);
/**
* 可优化位置
*/
//6pageStream对象绘制图片位置及大小已PDF文件右下角为原点x,y是图片左下角左边widthheight是图片的长和宽
//pageStream.drawImage(image, 450, 700,50,50);
//获取pdf宽度
float width = document.getPage(pageNo).getMediaBox().getWidth();
positionX = (float) (width * positionX / 750.0);
positonY = (float) (width * positonY / 750.0);
imageWidth = (float) (width * imageWidth / 750.0);
imageHeight = (float) (width * imageHeight / 750.0);
pageStream.drawImage(image, positionX, positonY,imageWidth,imageHeight);
pageStream.close();
//7保存PDF到指定路径
document.save(tempPath);
//8将输出路径转换成 File后续进行 OSS 上传
File file = new File(tempPath);
InputStream inputStream = new FileInputStream(file);
//获取当前时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
Date now = new Date();
String formattedDate = sdf.format(now);
resultPdfPath = OssBootUtil.upload(inputStream, formattedDate+".pdf");
//删除临时文件
file.delete();
//8关闭流
document.close();
pdfInputStream.close();
}catch (Exception e){
e.printStackTrace();
return Result.OK("pdf添加签名失败!");
}
return Result.OK("pdfPath", resultPdfPath);
}
/***************************************************************************/
/** /**
* pdf链接文件转换成多图片base64 * pdf链接文件转换成多图片base64
* @param pdfLink * @param pdfLink


Loading…
Cancel
Save