0

我正在使用 SpirePDF Free 将 docx 文件转换为 PDF 并返回浏览器。我在本地使用 Windows 11 操作系统,在服务器上使用 Ubuntu 20.4。问题是:本地文本对齐完全适合 1 页,但是在服务器上,文本块之间存在空格,这导致 pdf 被分成 2 页。

在此处输入图像描述

这是我用来将 docx 转换为 pdf 的代码:

public void savePdf(InputStream in, OutputStream out) {
        //Create Document object
        com.spire.doc.Document doc = new com.spire.doc.Document();

        //Load the file from disk.
        doc.loadFromStream(in, FileFormat.Docx);

        //create an instance of ToPdfParameterList.
        ToPdfParameterList ppl = new ToPdfParameterList();

        //embeds full fonts by default when IsEmbeddedAllFonts is set to true.
        ppl.isEmbeddedAllFonts(false);

        //set setDisableLink to true to remove the hyperlink effect for the result PDF page.
        //set setDisableLink to false to preserve the hyperlink effect for the result PDF page.
        ppl.setDisableLink(true);

        //Set the output image quality as 40% of the original image. 80% is the default setting.
        doc.setJPEGQuality(40);

        //Save to file.
        doc.saveToStream(out, FileFormat.PDF);
    }
4

0 回答 0