docx to xls-fo RRS feed

  • Question

  • Hello there I can from word-ui app create first xls and transform it to create a xls-fo file but how can I in command line create xls-fo file from .docx file ? After that I want use apache FOP to create pdf. (this is to try workaround for this issue/requirement
    Thursday, November 29, 2018 2:09 PM

All replies

  • Hi istiti,

    Please refer to the following code:

    package org.samples.docxconverters.xdocreport.pdf;
    import org.apache.poi.xwpf.converter.pdf.PdfConverter;
    import org.apache.poi.xwpf.converter.pdf.PdfOptions;
    import org.apache.poi.xwpf.usermodel.XWPFDocument;
    public class HelloWorldToPDF {
        public static void main(String[] args) {
        private static void createPDF() {
            try {
                long start = System.currentTimeMillis();
                // 1) Load DOCX into XWPFDocument
                InputStream is = new FileInputStream(new File(
                XWPFDocument document = new XWPFDocument(is);
                // 2) Prepare Pdf options
                PdfOptions options = PdfOptions.create();
                // 3) Convert XWPFDocument to Pdf
                OutputStream out = new FileOutputStream(new File(
                PdfConverter.getInstance().convert(document, out, options);
                System.err.println("Generate pdf/HelloWorld.pdf with "
                        + (System.currentTimeMillis() - start) + "ms");
            } catch (Throwable e) {

    For more information, please see the following links:

    XDocReport (Apache POI XWPF)

    Convert Word document to XSL-FO

    Converting Word documents to XSL-FO

    Hopefully it helps you.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Friday, November 30, 2018 2:40 AM
  • after trying this code my pdf is always 0octes/corrupted (even with simple pdf with hello world text)
    Friday, November 30, 2018 6:47 AM
  • Instead of adding yet another layer of complexity, as discussed @ MS Answers you should learn to format your documents properly using Styles.

    Paul Edstein
    [MS MVP - Word]

    Friday, November 30, 2018 7:50 AM