POI使用

1、通过poi生成word文档

            参考资料:https://blog.csdn.net/u012775558/article/details/79678701

            https://blog.csdn.net/owen_william/article/details/81290024

          官网:

                  https://poi.apache.org/


poi基本使用:

            http://www.cnblogs.com/LiZhiW/p/4313789.html?utm_source=tuicool&utm_medium=referral


2、将word转换为pdf文件

            参考资料:

                     https://www.programcreek.com/java-api-examples/?code=DistX/Learning/Learning-master/word%E6%8A%A5%E8%A1%A8%E7%94%9F%E6%88%90/xdocreport.samples-master/samples/fr.opensagres.xdocreport.samples.docx.converters/src/fr/opensagres/xdocreport/samples/docx/converters/pdf/ConvertDocxBigToPDF.java

          2.1、在pom.xml文件中添加依赖包

                     <dependency>

                             <groupId>com.lowagie</groupId>

                             <artifactId>itext</artifactId>

                             <version>2.1.7</version>

                             <type>jar</type>

                       </dependency>

                        <dependency>

                                  <groupId>fr.opensagres.xdocreport</groupId>

                                  <artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>

                                   <version>1.0.4</version>

                         </dependency>

           2.2、

           ```

      public static void convertPdf(String docxFilePath,String pdfFilePath) throws Exception{

                    File docxFile=new File(docxFilePath);

                    File pdfFile=new File(pdfFilePath);

                     //转换pdf文件

                     if(docxFile.exists()){

                              if(!pdfFile.exists()){

                                   InputStream inStream=new  FileInputStream(docxFilePath);

                                   XWPFDocument document = new XWPFDocument(inStream);

                                   //HWPFDocument document = new HWPFDocument(inStream);

                                    OutputStream out = new FileOutputStream(pdfFilePath);

                                     PdfOptions options = PdfOptions.create();         

                                //ExtITextFontRegistry fontProvider=ExtITextFontRegistry.getRegistry();

                                //options.fontProvider(fontProvider);

                                PdfConverter.getInstance().convert(document, out, options);

                    }else{

                              System.out.println("PDF文件已存在,无需再次转换");

                     }

                      }else{

                             }

                }

                 ```

            2.3、主方法调用

                  ```

                 String filepath = "C:/01_workplace/02_upload_workplace/LOI_01.docx";

                  String outpath = "C:/01_workplace/02_upload_workplace/LOI_01.pdf";

                  convertPdf(filepath,outpath);

                 ```

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
    远航的移动开发历程阅读 11,200评论 12 197
  • 使用首先需要了解他的工作原理 1.POI结构与常用类 (1)创建Workbook和Sheet (2)创建单元格 (...
    长城ol阅读 8,500评论 2 25
  • 1 什么是Apache POI2 Apache POI的组件3 安装Apache POI4 使用POI操作Word...
    艾剪疏阅读 73,205评论 34 86
  • 如果说 影子是为了光而存在,那我呢? ——影 我姓季,一个不算常见的姓氏。虽然很想说我是季茉的妹妹,可惜也只是想想...
    舒记阅读 338评论 0 0
  • 操作系统为了管理进程和资源,必须掌握每个进程和资源的当前状态.主要维护4个表:内存,I/O,文件和进程 内存表 1...
    知止9528阅读 2,120评论 0 9