这里有一些源代码可以让你打印任何文本文件:
public void print() {
//The desktop api can help calling other applications in our machine
//and also many other features...
Desktop desktop = Desktop.getDesktop();
try {
//desktop.print(new File("DocXfile.docx"));
desktop.print(new File("Docfile.pdf"));
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
也许它符合您的需求,因为您没有提供更多细节.