如何在Java中打印出DOCX文件?

问题描述:

我创建了一些Java代码,允许我打印png,pdf,jpg等,但是我卡在docx文件以及可能的其他文件类型上,

i have created some java code that allows me to print png,pdf,jpg etc but i am stuck on docx files and possibly other file types,

当前我正在使用以下代码:

currently i am using the code below :

 if (extension.equals("txt")) {
            psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
        } else if (extension.equals("png")) {
            psInFormat = DocFlavor.INPUT_STREAM.PNG;
        } else if (extension.equals("gif")) {
            psInFormat = DocFlavor.INPUT_STREAM.GIF;
        } else if (extension.equals("jpg")) {
            psInFormat = DocFlavor.INPUT_STREAM.JPEG;
        } else if (extension.equals("pdf")) {
            psInFormat = DocFlavor.INPUT_STREAM.PDF;
        }

要确定文件类型是哪种类型,以为该doc类型创建正确的输入流的ps,我可以修改此代码以包含doc文件吗?

to determine what the file type is to create the ps of the right input stream for that doc type, could i mod this code to include doc files ?

无法直接使用DocFlavor做到这一点

There's no way to do this directly with DocFlavor

看看POI项目

http://poi.apache.org/hwpf/index.html