步骤1:引入依赖我们需要引入Apache POI和OpenPDF两个库来实现Word和PDF之间的转换,具体步骤如下:在Maven项目中,可以在pom.xml中添加以下依赖:xml 体验AI代码助手 代码解读复制代码 -- OpenPDF --><dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artifactId> <version> 在这个方法中,我们先使用Apache POI库读取Word文档,并使用OpenPDF库创建一个PDF文件。然后,我们使用代码设置页面事件来添加水印和签名盖章。 本文使用了Apache POI和OpenPDF两个库来实现Word和PDF之间的转换。 在实现过程中,我们使用了PdfPageEvent接口来添加水印和签名,使用Apache POI库来读取Word文档,使用OpenPDF库来创建和编辑PDF文件。
OpenPDF OpenPDF[11] OpenPDF是一个Java库,使用LGPL和MPL开源许可证。可以拥有创建和编辑PDF文件。 OpenPDF是iText的LGPL/MPL开源后继产品,它基于iText 4 svn标签的一个分支。 地址:https://github.com/LibrePDF/OpenPDF 11. x-easypdf x-easypdf[12] x-easypdf基于pdfbox构建而来,极大降低使用门槛,以组件化的形式进行 pdfbox_reading_text.html [10] java解析pdf获取pdf中内容信息 - 掘金: https://juejin.cn/post/7231795067072954429 [11] OpenPDF : https://github.com/LibrePDF/OpenPDF [12] x-easypdf: https://gitee.com/xsxgit/x-easypdf [13] freemarker
官网 https://pdfbox.apache.org/ 下面是一个仓库的镜像 https://github.com/apache/pdfbox 0x04:OpenPDF OpenPDF是一个 OpenPDF是iText的LGPL / MPL开源后继产品,它基于iText 4 svn标签的一个分支。 仓库 https://github.com/LibrePDF/OpenPDF 0x05:x-easypdf x-easypdf基于pdfbox构建而来,极大降低使用门槛,以组件化的形式进行pdf的构建
$refs.openPdf.preview(item.url) 使用: <previewPdf ref="<em>openPdf</em>"></previewPdf> <!
public static void main(String[] args) throws Exception { pdfboxTest5(); } private static void pdfboxTest5() throws DocumentException, IOException { File file = new File("E:\\sss\\test5.pdf"); Document doc = new Document(PageSize.A4); String tempFileN
"0" /> <Button Content="Open PDF" Grid.Row="1" HorizontalAlignment="Left" Margin="10" Click="<em>OpenPDF</em>_Click { return false; } return true; } private void <em>OpenPDF</em>_Click
# 用Spring Initializr创建项目,记得带上这些“彩礼”:- Spring Web (提供REST API)- Apache POI (处理Word)- PDFBox (处理PDF)- OpenPDF -- 另一种PDF生成选择:OpenPDF --> <dependency> <groupId>com.github.librepdf</groupId> <artifactId >openpdf</artifactId> <version>1.3.30</version> </dependency></dependencies>第三章:详细实现步骤(带完整代码 *;@Servicepublic class WordToPdfService { /** * 方法1:使用Apache POI + OpenPDF(适合.doc和.docx) pdfFile); } }}第五章:总结与心得5.1 转换效果对比Word转PDF:成功率高,就像把新鲜水果做成果酱——能很好地保存原味格式基本保留,布局不乱推荐使用Apache POI + OpenPDF
* * 打开 PDF 文件内容 * @return string * @author chendashengpc */ public function openPdf chendashengpc */ public function PdfToTxt(FileInterface $file) { return $file->openPdf
OpenPDF :OpenPDF是一个免费的Java库,用于使用LGPL和MPL开源许可创建和编辑PDF文件。OpenPDF基于iText的一个分支。
当然除此之外,还有很多开源项目是基于html生成pdf的,比如经典的itext,openpdf、openhtmltopdf、jasper、x-easypdf等。
jimureport-spring-boot-starter</artifactId> <version>1.5.0</version> </dependency> #升级日志 重点修复fastjson漏洞,建议大家尽快升级;另外采用openpdf
之前LGPL/MPL许可协议下的iText现在在GitHub上有一个活跃的分支——OpenPDF。当然,iText Software NV拥有对iText的所有支持产权和授予权。
savedFilePath:res.savedFilePath }) } }) } } }) }, openPDF