java - Java:将 ms word 转换为 pdf 时,标题空间中不需要的空格
问题描述
我正在使用以下代码将现有单词转换为 PDF。但是在创建页面时,生成的 PDF 的第二页包含不需要的页眉空间。是否可以从第二页中删除此空间?在输入文件中,我在第一页有一个更大的标题,而我在第二页只有一个小标题。
public static void main(String[] args) throws Exception {
String inputFile = "input word.docx";
String outputFile = "output.pdf";
if ((args != null) && (args.length == 2)) {
inputFile = args[0];
outputFile = args[1];
}
FileInputStream in = new FileInputStream(inputFile);
XWPFDocument document = new XWPFDocument(in);
File outFile = new File(outputFile);
OutputStream out = new FileOutputStream(outFile);
PdfOptions options = null;
PdfConverter.getInstance().convert(document, out, options);
}
添加的依赖项:
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/org.apache.poi.xwpf.converter.pdf -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
<version>1.0.6</version>
</dependency>
解决方案
推荐阅读
- bash - 从终端直接执行 docker 可以正常工作,但从 .sh 脚本内部执行时不行?
- sql - 获取帖子 ID 列表的评论时间戳(created_utc),其中他们在任何 2 个节点之间有共同的评论作者 - Reddit 数据集
- c# - 无法获取http响应内容
- ibm-doors - 如何在 IBM 门的两列中划分值
- javascript - 错误:ENOENT:没有这样的文件或目录,打开尝试使用 fs 访问目录时
- python - (Django)类型对象'User'没有属性'USERNAME_FIELD'
- javascript - 对象不会在控制台中返回
- typescript - 使用 infer 和 typeof 在 Typescript 中创建工厂
- python - 如何修复我的 python kivy 文件夹监控应用程序崩溃
- python - 避免 x 既不增加也不减少:{}.".format(x) 计算 auc 分数时