java使用Abobe Acrobat DC生成模板
一、利用word生成一個文檔轉成pdf
說明:轉換成pdf格式
二、Abobe Acrobat DC圖解
利用Abobe Acrobat DC打開pdf
步驟:文件 ---->創(chuàng)建------>創(chuàng)建表單----->選擇文件(你轉換成pdf文件)
這里是所要增加的文本域、圖片域等功能按鈕
在你需要的位置增加你說要的功能完成之后進行保存
三、java后臺代碼
環(huán)境maven
<dependency> <groupId>com.itextpdf</groupId> <artifactId>itext7-core</artifactId> <version>7.1.13</version> <type>pom</type> </dependency>
生成的模板文件放到適當的位置
所需要生成新的pdf代碼
public @ResponseBody Object getFaceVerificationPdf(GzFaceVerification gzFaceVerification, HttpServletRequest request) throws IOException { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { try (PdfDocument document = new PdfDocument(new PdfReader( new ClassPathResource("static/moban.pdf").getInputStream()), new PdfWriter(outputStream))) { PdfAcroForm pdfAcroForm = PdfAcroForm.getAcroForm(document, true); //對圖片進行處理(如果不處理在模板中顯示不出圖片) PdfFormField pdfFormField = pdfAcroForm.getField("frontIdCardUrl"); InputStream is = new FileInputStream(new File(gzFaceVerification.getFrontIdCardUrl())); String str = Base64.encodeBytes(StreamUtil.inputStreamToArray(is)); pdfFormField.setValue(str); pdfAcroForm.addField(pdfFormField); PdfFormField pdfFormField1 = pdfAcroForm.getField("reverseIdCardUrl"); InputStream is1 = new FileInputStream(new File(gzFaceVerification.getReverseIdCardUrl())); String str1 = Base64.encodeBytes(StreamUtil.inputStreamToArray(is1)); pdfFormField1.setValue(str1); pdfAcroForm.addField(pdfFormField1); PdfFormField pdfFormField2 = pdfAcroForm.getField("photo"); InputStream is2 = new FileInputStream(new File(gzFaceVerification.getPhoto())); String str2 = Base64.encodeBytes(StreamUtil.inputStreamToArray(is2)); pdfFormField2.setValue(str2); pdfAcroForm.addField(pdfFormField2); pdfAcroForm.getField("frontIdCardUrl").setValue(gzFaceVerification.getFrontIdCardUrl()); pdfAcroForm.getField("reverseIdCardUrl").setValue(gzFaceVerification.getReverseIdCardUrl()); pdfAcroForm.getField("photo").setValue(gzFaceVerification.getPhoto()); pdfAcroForm.getField("comparisonResults").setValue(gzFaceVerification.getComparisonResults()); pdfAcroForm.getField("createTime").setValue(gzFaceVerification.getCreateTime()); pdfAcroForm.flattenFields(); } HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_PDF); httpHeaders.setContentDispositionFormData("attachment", "test.pdf", Charset.forName("UTF-8")); return ResponseEntity.ok().headers(httpHeaders).body(outputStream.toByteArray()); } }
到此這篇關于java使用Abobe Acrobat DC生成模板的文章就介紹到這了,更多相關Abobe Acrobat DC生成模板內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
詳解SpringBoot 使用Spring Initializr 快速構建工程(官方推薦)
本篇文章主要介紹了SpringBoot 使用Spring Initializr 快速構建工程(官方推薦),非常具有實用價值,需要的朋友可以參考下2017-10-10如何解決EasyExcel導出文件LocalDateTime報錯問題
這篇文章主要介紹了如何解決EasyExcel導出文件LocalDateTime報錯問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06詳解SpringBoot修改啟動端口server.port的四種方式
這篇文章主要介紹了詳解SpringBoot修改啟動端口server.port的四種方式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-07-07Java利用DelayQueue實現(xiàn)延遲任務代碼實例
這篇文章主要介紹了Java利用DelayQueue實現(xiàn)延遲任務代碼實例,DelayQueue?是一個支持延時獲取元素的阻塞隊列,?內部采用優(yōu)先隊列?PriorityQueue?存儲元素,同時元素必須實現(xiàn)?Delayed?接口,需要的朋友可以參考下2023-12-12SpringBoot集成企業(yè)微信開發(fā)的實現(xiàn)
本文將詳細介紹如何使用?Spring?Boot?集成企業(yè)微信開發(fā),通過企業(yè)微信?API?可以實現(xiàn)企業(yè)內部的一些自動化業(yè)務流程,提高工作效率,感興趣的可以了解一下2023-07-07