【问题标题】:Is there any way to convert docx to pdf in android using java?有没有办法使用java在android中将docx转换为pdf?
【发布时间】:2019-09-22 18:21:39
【问题描述】:

我尝试在 android 中使用 Apache POI 但无法成功。 Apache POI 中的大部分资源都在 java spring 框架中使用。 Apache POI for android 仅用于 xls 表我如何将 DOCX/DOC 转换为 pdf。

https://github.com/SUPERCILEX/poi-android

【问题讨论】:

    标签: java android pdf type-conversion docx


    【解决方案1】:

    我知道了:

    private byte[] toPdf(ByteArrayOutputStream docx) {
        InputStream isFromFirstData = new ByteArrayInputStream(docx.toByteArray());
    
        XWPFDocument document = new XWPFDocument(isFromFirstData);
        PdfOptions options = PdfOptions.create();
    
        //make new file in c:\temp\
        OutputStream out = new FileOutputStream(new File("c:\\tmp\\HelloWord.pdf"));
        PdfConverter.getInstance().convert(document, out, options);
    
        //return byte array for return in http request.
        ByteArrayOutputStream pdf = new ByteArrayOutputStream();
        PdfConverter.getInstance().convert(document, pdf, options);
    
        document.write(pdf);
        document.close();
        return pdf.toByteArray();
    }
    

    【讨论】:

    • 它只能在JVM机器上工作,不能在使用dalvik虚拟机的android上工作。
    猜你喜欢
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 2017-09-07
    • 2019-09-24
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多