我正在运行一个简单的 Java 应用程序 (JDK 1.8)。我的主要目标是访问文档(不同格式),转换为 PDF,然后使用 PDFClown 计算页数。
我可以通过在我的项目目录(在我的计算机上)上引入文档来做到这一点。问题是当我尝试访问另一台服务器上的文档时。
org.artofsolving.jodconverter.office.OfficeException: could not load document: Unsupported URL : "type detection failed"
这是我的代码:
public static void main(String[] args) throws FileNotFoundException {
OfficeManager officeManager = new DefaultOfficeManagerConfiguration().buildOfficeManager();
officeManager.start();
String path = "\\\\serverIP\\documents\\test.doc";
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
String outFile = path.substring(0, path.lastIndexOf(".")) + ".pdf";
converter.convert(new File(path), new File(outFile));
Document document = new Document(new org.pdfclown.files.File(outFile));
int countPages = document.getNumberOfPages();
System.out.println(countPages);
officeManager.stop();
}
我做错了什么?
最佳答案
您无法使用简单的 File
类以这种方式访问远程文件。
您必须 mount your folder as network drive并使用正常的文件系统路径访问文件。
或者使用特殊的库通过SMB协议(protocol)传输文件而无需挂载。 请参阅此处的示例:connecting to shared folder in windows with java
关于java - LibreOffice 4.4.3 - 使用不同服务器上的 jodconverter 访问文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30807416/