首页 文章

PdfStamper更改字体

提问于
浏览
0

我将我的信件写在一个程序中并以PDF格式导出 . 我最近实现了一个小的控制台程序,它应该迭代每个页面并设置我的特殊设计字母(包含我的地址等)作为背景 .

问题是,我的信件是用Calibri写的 . 在使用pdf压模之前,原始PDF看起来很棒,在设置背景后,(未修改的文本)的样式看起来有点不同 .

在屏幕截图中看到我的意思 .

Screenshot

我无法向我解释,因此我认为这可能是一个错误 . 你有什么建议吗?

我的代码在这里 .

public static void main(String[] args) throws IOException, DocumentException {
    PdfBackgroundSetter.setBackgroundToPdf(args[0], args[1], args[2]);
}

public static void setBackgroundToPdf(String inputContentPdfPath, String outputPdfPath, String inputBackgroundPdfPath) throws IOException, DocumentException {
    PdfReader inputContentReader = new PdfReader(inputContentPdfPath);
    PdfStamper outputStamper = new PdfStamper(inputContentReader, new FileOutputStream(outputPdfPath));

    PdfReader inputBackgroundReader = new PdfReader(inputBackgroundPdfPath);
    PdfImportedPage backgroundPage = outputStamper.getImportedPage(inputBackgroundReader, 1);

    int numberOfPages = inputContentReader.getNumberOfPages();

    for (int i = 1; i <= numberOfPages; i++) {
        outputStamper.getUnderContent(i).addTemplate(backgroundPage, 0, 0);
    }
    outputStamper.close();
    inputContentReader.close();
    inputBackgroundReader.close();
}

可以在此处找到稍加修改(匿名)的PDF文件:

content.pdf

background.pdf

1 回答

  • 0

    正如@Chris已经说过,这基本上是由Adobe Reader / Acrobat引入的工件 . 它尤其取决于相关的Adobe Acrobat / Reader版本,可以通过不在后台PDF中使用透明组来防止 .

    详情

    我只能为某些Adobe软件版本Acrobat 9.5重现这个问题,而不是当前的问题,但我在Adobe Reader XI中看不到问题 .

    在Acrobat 9.5中将纯文本内容和内容与背景合并:

    Content in Acrobat 9.5

    Content with background in Acrobat 9.5

    阅读器XI中的简单内容和内容与背景合并:

    Content in Reader XI

    Content with background in Reader XI

    该工件似乎与透明组在后台文件中使用的事实有关 . 删除后台文件中的所有透明组后,我得到了这个:

    在Acrobat 9.5中,普通内容和内容与没有透明度组的背景合并:

    Content in Acrobat 9.5

    Content with background without transparency groups in Acrobat 9.5

    在最近的Adobe Acrobat和Reader版本中,透明度组的处理实际上已经有了很多改进 . 我一直都知道与实际透明度问题和淘汰赛组有关的这些改进,但这似乎是另一个 .

相关问题