使用iTextSharp合并pdf文件的内容 [英] Merge content of pdf files using iTextSharp

查看:264
本文介绍了使用iTextSharp合并pdf文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将一个pdf文件的内容放在另一个pdf文件中的特定位置(例如两段之间)并让原始内容自动向下移动以使其不会支持新内容?

Is it possible to place the content of one pdf file to a specific place in another one (e.g. between two paragraphs) and have the original content automatically shift downwards so it does not underlay the new one?

如果没有,是否至少可以获得pdf页面内容部分的高度?

If not, is it at least possible to get a height of only the content part of a pdf page?

我有一个数字使用AcroForms模板,其中一个是包含多个页面的主模板,我需要在特定位置标记并插入其他文件。

I have a number of templates with AcroForms, where one is the main template containing several pages and I need to stamp and insert the other files into it at specific places.

我可以使用 PdfWriter PdfTemplate 使用绝对定位来组装输出,但这看起来有点难看。

I can do that using PdfWriter and PdfTemplate to assemble the output using absolute positioning, but that seems a bit ugly.

推荐答案

当你在这里提出多个问题时,我会在回答时引用相应的问题。

As you ask multiple questions here, I'll quote the respective question when answering.


是否可以将一个pdf文件的内容放在另一个pdf文件的特定位置(例如两段之间)并且具有原点al content会自动向下移动所以它不会支持新的内容吗?

Is it possible to place the content of one pdf file to a specific place in another one (e.g. between two paragraphs) and have the original content automatically shift downwards so it does not underlay the new one?

PDF 格式你可以(轻松)回流。虽然你的问题没有提到最糟糕的回流情况(这会是插入一些文字,例如句子,插入现有段落),但这已经很难了。向下移动段落,例如你不希望任何页脚线也向下移动;遗憾的是,页脚行不会(必然)标记为页脚行。您可能希望移动属于内容但不属于背景图像的图像;遗憾的是,图像未标记为前景或背景图像。等等。

PDF is not a format you can (easily) reflow. And while your question does not refer to the worst case of reflowing (this would be insertion of some text, e.g. a sentence, into an existing paragraph), it is already difficult. When moving down the paragraphs, e.g. you wouldn't want any footer lines to also move down; unfortunately footer lines are not (necessarily) marked as footer lines. You would want to move images belonging to the content but not background images; unfortunately images are not marked as foreground or background images. Etc. pp.

本质上:iText没有方便的方法来插入这样的段落,任何拥有它们的库都会经常产生不良结果。

In essence: iText does not have convenience methods for such a paragraph insertion, and any library that has them, will every so often create undesirable results.


如果没有,是否至少可以获得pdf页面内容部分的高度?

If not, is it at least possible to get a height of only the content part of a pdf page?

PDF页面的内容部分是什么?你的意思是排除页眉和页脚?如上所述,页眉和页脚没有这样标记,因此不能(可靠地)自动识别。因此,。或者你的意思是所有页面内容都是最小的矩形?在这种情况下,请查看 ShowTextMargins =http://itextpdf.com/book/ =nofollow> iText in Action - 2nd Edition 。此示例查找文本,但您可以通过扩展其中使用的 TextMarginFinder 来简化它,不仅可以对renderText事件做出反应,还可以对renderImage做出反应。但我担心裁剪路径可能会被忽略。

What is the content part of a PDF page? Do you mean excluding headers and footers? As mentioned above, headers and footers are not marked as such and, therefore, cannot (dependably) be automatically recognized. Thus, no. Or do you mean the smallest rectangle all page content is in? In that case have a look at the sample ShowTextMargins from chapter 15 of iText in Action — 2nd Edition. This sample looks for text but you can easily generalize it by extending the TextMarginFinder used there to not only react to renderText events but also to renderImage. I'm afraid, though, that clipping paths might be ignored.


我有一些AcroForms的模板,其中一个是主要的包含多个页面的模板,我需要在特定位置标记并插入其他文件。

I have a number of templates with AcroForms, where one is the main template containing several pages and I need to stamp and insert the other files into it at specific places.

你提到了Acroforms。表单元素是PDF页面内容的一部分,它们与注释相关联。注释比页面内容更容易移动,但如果您的页面内容注释属于彼此,则必须同时移动两者。

You mention Acroforms. Form elements are not part of the PDF page content, they are associated to it as annotations. Annotations are easier to move around than page content, but if you have page content and annotations belonging to each other, you will have to move both in concert.


我可以使用PdfWriter和PdfTemplate来使用绝对定位来组合输出,但这看起来有点难看。

I can do that using PdfWriter and PdfTemplate to assemble the output using absolute positioning, but that seems a bit ugly.

这看起来有多难看?输出是丑陋的还是产生它的代码?

In what way does that seem ugly? Is the output ugly or the code producing it?

这篇关于使用iTextSharp合并pdf文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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