【发布时间】:2018-02-24 20:11:15
【问题描述】:
我正在尝试使用 Apache 的 POI 将 word 文档转换为 PDF。
但是,它正在转换具有更大行高/段落间距的文件。
从 Word 文件中提取:
与转换后的 PDF 完全相同的摘录:
如您所见,每个段落的间距都比最初预期的要大得多,甚至会导致页面跳转。
我使用的代码如下:
try {
InputStream doc = new FileInputStream(new File("random.docx"));
XWPFDocument document = new XWPFDocument(doc);
PdfOptions options = PdfOptions.create();
OutputStream out = new FileOutputStream(new File("random.pdf"));
PdfConverter.getInstance().convert(document, out, options);
System.out.println("Done");
} catch (FileNotFoundException ex) {
System.out.println(ex.getMessage());
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
This 是我正在使用的输入文件。
依赖包括以下内容:
我需要一种方法来消除这种间距,或者至多将其缩小到尽可能接近原始方式。
非常感谢您的意见(无论是什么)。
【问题讨论】:
-
您是否有可能使用脚本语言 (PowerShell) 来完成这项工作,或者 POI 是“必须要求”吗?
-
我唯一的要求是获得大量转换为 PDF 的文档。请告诉我有关此 PowerShell 的更多信息
-
这是一个有用的链接:stackoverflow.com/questions/16534292/…
标签: java pdf ms-word apache-poi file-conversion