POI使用

作者: sckehan | 来源:发表于2019-04-03 11:07 被阅读0次

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);

                 ```

相关文章

网友评论

      本文标题:POI使用

      本文链接:https://www.haomeiwen.com/subject/nveabqtx.html