将pdfs与itext相结合 - 呈现为纵向的横向页面 [英] Combining pdfs with itext - landscape pages rendered as portrait

查看:315
本文介绍了将pdfs与itext相结合 - 呈现为纵向的横向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在维护一个使用itext来组合多个横向和纵向pdf的遗留应用程序。当将由同一应用程序生成的pdf与其他pdf组合时,此过程正常工作,它将横向渲染为portait并切断内容。

I'm maintaining a legacy application that uses itext to combine multiple landscape and portrait pdfs. This process is working fine when combining pdfs produced by the same application, with other pdfs it renders landscape as portait and cuts off content.

问题:结构中是否存在属性可以导致渲染这种差异的PDF格式?

Question: Are there properties in the structure of the pdf that can cause such difference in rendering?

谢谢!

推荐答案

您所描述的行为只会发生如果你遵循坏的例子。当您按照官方文档进行操作时不会发生这种情况。

The behavior you're describing only occurs if you follow bad examples. It doesn't occur when you follow the official documentation.

虽然您没有提供任何源代码,但我很确定您使用 PdfWriter 实例,并将现有页面添加到直接内容此实例使用 addTemplate()方法。这是(正如我多次向未阅读文档的人指出的那样)错误。

Although you didn't provide any source code, I'm pretty sure that you use a PdfWriter instance and that you add existing pages to the direct content of this instance using the addTemplate() method. This is (as I have pointed out many times to people who don't read the documentation) wrong.

您需要替换合并过程并使用 PdfCopy PdfSmartCopy 连接PDF文档。请查看 MergeForms (合并)表格)和 FillFlattenMerge2 (介绍) PdfSmartCopy 以便生成的文件大小保持较低的灵感示例。如果您的应用程序真的很旧,您可能找不到 addDocument()方法。

You need to replace the merging process and use PdfCopy or PdfSmartCopy to concatenate PDF documents. Take a look at the MergeForms (merging forms) and FillFlattenMerge2 (introducing PdfSmartCopy so that the resulting file size remains low) examples for inspiration. If your application is really old, you may not find the addDocument() method.

在这种情况下,你需要使用旧的示例,例如 Concatenate 示例:

In that case, you need to use old examples, such as the Concatenate example:

Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileOutputStream(RESULT));
document.open();
PdfReader reader;
int n;
for (int i = 0; i < files.length; i++) {
    reader = new PdfReader(files[i]);
    n = reader.getNumberOfPages();
    for (int page = 0; page < n; ) {
        copy.addPage(copy.getImportedPage(reader, ++page));
    }
    copy.freeReader(reader);
    reader.close();
}
document.close();

这篇关于将pdfs与itext相结合 - 呈现为纵向的横向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆