利用freemark進行pdf的轉換

2021-09-28 16:34:24 字數 1782 閱讀 7768

1. 對pom檔案進行引入

org.springframework.boot

spring-boot-starter-freemarker

org.xhtmlrenderer

flying-saucer-pdf

9.0.9

org.springframework

spring-test

release

2. 轉換的流程思路 

(1) 讀取靜態檔案模板,將資料進行動態顯示

(2)利用freemark模板生成器將ftl模板生成html靜態檔案

(3)將靜態檔案轉化為流的方式,利用pdf模板將流轉化為pdf檔案

(4)可以將pdf檔案轉化為流,上傳到檔案系統

3. 方法**(後台**)

@override

public rgetredset(integer id) catch (ioexception e)

//通過id查詢公文資訊

oaofficialdocument oaofficialdocument = oaofficialdocumentservice.getbyid(id);

//存放頁面輸出的引數

mapparam = new hashmap();

//用於頁面繫結引數

param.put("oaofficialdocument", oaofficialdocument);

//獲取html轉化為pdf物件

itextrenderer renderer = new itextrenderer();

try catch (documentexception e) catch (ioexception e)

try (stringwriter writer = new stringwriter();) catch (templateexception e) catch (ioexception e)

renderer.layout();

//用來定義乙個儲存pdf的流資訊

byte filebytes = null;

try (bytearrayoutputstream bytearrayoutputstream = new bytearrayoutputstream();) catch (documentexception e) catch (ioexception e)

multipartfile file = null;

//將byte陣列轉化為寫入流

try (inputstream inputstream = new bytearrayinputstream(filebytes);) catch (ioexception e)

//呼叫遠端的fegin介面將檔案上傳到minio中

rpdffile = remotefileuploadservice.upload(file);

log.info("套紅結束。。。。。。。。。。");

return pdffile;

}

4. 前台**

style="font-family: simhei;">

三門峽社會管理職業學院

三門峽技師學院檔案$

PDF分析文字(1)利用python對PDF的讀取

1,安裝第三方庫檔案 pdfminer3k。安裝方式 pip install pdfminer3k 中文參考文件 3,資料獲取思路 1 通過pdf轉html,再利用爬蟲技術解決,目前來說這方面的技術比較成熟,而且參考很多。2 通過pdf轉為txt格式,再通過字元提取的方式處理。這樣的方式容易理解。3...

利用PDFLib生成PDF文件

本文 生成的pdf文件效果圖 一 pdf介紹 pdf是portable document format的縮寫,pdf檔案格式是國際通用的電子文件交換事實標準,被許多國家採用作為電子文件交換。pdf檔案可以在各種平台下閱讀 編輯 發布。該檔案格式支援字型 影象 甚至任何附件的嵌入。您可以通過免費的ad...

利用itext生成pdf文件

最近在用itext這一開源庫生成pdf檔案,小有所悟,故寫下。第一步,建立乙個 itextsharp.text.document 物件的例項 document document new document 第二步,為該 document 建立乙個 writer 例項 pdfwriter.getinst...