Java:using apache POI how to convert ms word file to pdf?

后端 未结 7 2152
旧巷少年郎
旧巷少年郎 2020-12-02 13:43

By using apache POI how to convert ms word file to pdf?

I an using the following code but its not working giving errors I gues

7条回答
  •  醉话见心
    2020-12-02 14:33

    This save my day, i load docx file from an url and convert it to pdf:

    pom.xml

    
        org.apache.poi
        poi
        3.13
    
    
        org.apache.poi
        poi-ooxml
        3.13
    
    
        fr.opensagres.xdocreport
        org.apache.poi.xwpf.converter.pdf
        LATEST
    
    

    main_class

    public String wordToPDFPOI(String url) throws Exception {
        InputStream doc = new URL(url).openStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
        XWPFDocument document = new XWPFDocument(doc);
        PdfOptions options = PdfOptions.create();
        PdfConverter.getInstance().convert(document, baos, options);
        String base64_encoded = Base64.encodeBytes(baos.toByteArray());
    
        return base64_encoded;
    }
    

提交回复
热议问题