document4j看起来像是一个很棒的应用程序接口,我很乐意使用它。我只想在我的mac (安装了Microsoft office )上将docx批量转换为pdf。
我已经写了这段代码,但是我得到了LocalConverter无法解析的错误。我做错了什么?我是否导入了正确的jars?
package Input;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.concurrent.Future;
import org.xml.sax.SAXException;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
public class TBB {
public static FileInputStream convert(InputStream docxInputStream) throws FileNotFoundException {
FileInputStream inputStream = null;
try (OutputStream outputStream = new FileOutputStream(new File("/Users/sebastianzeki/mydoc.docx"))) {
IConverter converter = LocalConverter.builder().build();
converter
.convert(docxInputStream).as(DocumentType.DOCX)
.to(outputStream).as(DocumentType.PDF)
.prioritizeWith(1000).schedule();
inputStream = new FileInputStream("/Users/sebastianzeki/mydoc.docx");
} catch (Exception e) {
e.getMessage();
}
return inputStream;
}
}发布于 2019-08-02 02:21:11
documents4j与Mac不兼容。查看您的堆栈跟踪,您会发现类似这样的内容:com.documents4j.throwables.ConverterAccessException: Unable to run script: /Applications/Tomcat-9.0.1/temp/1564683313105-0/word_start775650809.vbs Documents4j正在幕后运行生成的vbScript。据我所知,mac没有办法运行vbScript。我必须在我的服务器上安装一台安装了Word的Windows,并使用documents4j远程api调用windows vm进行转换。
https://stackoverflow.com/questions/52783708
复制相似问题