首页 > 解决方案 > 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>

这是我输入word文档的第二页看起来像 在此处输入图像描述

这是我当前生成的输出pdf 在此处输入图像描述

标签: javapdfapache-poixwpf

解决方案


推荐阅读