| | |
| | | put("seal1", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); |
| | | put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create()); |
| | | }}, finalUrl); |
| | | wordToPdf(finalUrl); |
| | | wordToPdf(finalUrl,sealUrl); |
| | | |
| | | String replace = finalUrl.replace(".docx", ".pdf"); |
| | | /* String replace = finalUrl.replace(".docx", ".pdf"); |
| | | CompletableFuture.supplyAsync(() -> { |
| | | try { |
| | | stamperCheckMarkPDF(replace,replace,sealUrl); |
| | |
| | | }).exceptionally(e -> { |
| | | e.printStackTrace(); |
| | | return null; |
| | | }); |
| | | });*/ |
| | | |
| | | InsOrder insOrder = new InsOrder(); |
| | | insOrder.setId(insReportMapper.selectById(id).getInsOrderId()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void wordToPdf(String path) { |
| | | public void wordToPdf(String path,String sealUrl) { |
| | | CompletableFuture.supplyAsync(() -> { |
| | | try { |
| | | wordToPdf(path, path.replace(".docx", ".pdf")); |
| | | wordToPdf(path, path.replace(".docx", ".pdf"),sealUrl); |
| | | return null; |
| | | } catch (Exception e) { |
| | | throw new ErrorException("转换失败"); |
| | |
| | | }); |
| | | } |
| | | |
| | | public String wordToPdf(String wordPath, String pdfPath) { |
| | | public String wordToPdf(String wordPath, String pdfPath,String sealUrl) { |
| | | FileOutputStream os = null; |
| | | try { |
| | | //凭证 不然切换后有水印 |
| | |
| | | return null; |
| | | } |
| | | //生成一个空的PDF文件 |
| | | File file = new File(pdfPath); |
| | | File file = new File(pdfPath.replace(".pdf","-1.pdf")); |
| | | os = new FileOutputStream(file); |
| | | //要转换的word文件 |
| | | com.aspose.words.Document doc = new com.aspose.words.Document(wordPath); |
| | | doc.save(os, SaveFormat.PDF); |
| | | |
| | | //添加骑缝章 |
| | | stamperCheckMarkPDF(pdfPath.replace(".pdf","-1.pdf"),pdfPath,imgUrl + "/" +sealUrl); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | |
| | | */ |
| | | public static com.itextpdf.text.Image[] slicingImages(String Path, int n) throws IOException, BadElementException { |
| | | com.itextpdf.text.Image[] nImage = new com.itextpdf.text.Image[n]; |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | BufferedImage img = ImageIO.read(new File(Path)); |
| | | |
| | | int h = img.getHeight(); |
| | | int w = img.getWidth(); |
| | | |
| | |
| | | }else {//前n-1块均匀切 |
| | | subImg = img.getSubimage(i * sw, 0, sw, h); |
| | | } |
| | | |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | ImageIO.write(subImg,Path.substring(Path.lastIndexOf('.')+1),out); |
| | | nImage[i] = com.itextpdf.text.Image.getInstance(out.toByteArray()); |
| | | out.flush(); |
| | | out.reset(); |
| | | |
| | | } |
| | | return nImage; |
| | | } |
| | |
| | | PdfReader reader = new PdfReader(infilePath);//选择需要印章的pdf |
| | | PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outFilePath));//加完印章后的pdf |
| | | |
| | | |
| | | com.itextpdf.text.Rectangle pageSize = reader.getPageSize(1);//获得第一页 |
| | | float height = pageSize.getHeight(); |
| | | float width = pageSize.getWidth(); |
| | |
| | | int nums = reader.getNumberOfPages(); |
| | | com.itextpdf.text.Image[] nImage = slicingImages(picPath,nums);//生成骑缝章切割图片 |
| | | |
| | | |
| | | for(int n=1;n<=nums;n++){ |
| | | PdfContentByte over = stamp.getOverContent(n);//设置在第几页打印印章 |
| | | com.itextpdf.text.Image img = nImage[n-1];//选择图片 |
| | | img.setAbsolutePosition(width-img.getWidth(),height/2-img.getHeight()/2);//控制图片位置 |
| | | float newHeight = 100f; |
| | | float newWidth = img.getWidth()/(img.getHeight()/100); |
| | | img.scaleAbsolute(newWidth,newHeight);//控制图片大小 |
| | | img.setAbsolutePosition(width-newWidth,height/2-newHeight/2);//控制图片位置 |
| | | over.addImage(img); |
| | | } |
| | | stamp.close(); |