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文件中添加依赖包

                    

                             com.lowagie

                             itext

                             2.1.7

                             jar

                      

                       

                                  fr.opensagres.xdocreport

                                  org.apache.poi.xwpf.converter.pdf

                                   1.0.4

                        

           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使用)