如何复制表单域PdfWriter不PdfCopy在iTextSharp的 [英] How to copy form fields with PdfWriter not PdfCopy in iTextSharp

查看:726
本文介绍了如何复制表单域PdfWriter不PdfCopy在iTextSharp的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想合并两个PDF文件(仅适用于选定的页面),并添加自定义页眉和页脚他们。

I would like to merge two PDF files (only selected pages) and add custom headers and footers to them.

所以我不使用 PdfCopy ,简单地复制页面,而不改变它。 我用的是 PdfWriter

Therefore I do not use PdfCopy that simply copies the page without altering it. I use the PdfWriter.

现在的问题是我不知道如何复制AcroFields,Acroforms,注释和一切,除了内容与 PdfWriter

The problem is I do not know how to copy AcroFields, Acroforms, Annotations and everything else except content with the PdfWriter.

你知道如何做到这一点?

Do you know how to do this?

推荐答案

您想要使用 PdfWriter GetImportedPage 方法$ C>类。这一切都复制到 PdfImportedPage ,你可以再使用。

You want to use the GetImportedPage method of the PdfWriter class. This copies everything into a PdfImportedPage that you can then use.

PdfReader pdfReader = new PdfReader(originalFile);
PdfImportedPage importedPage = pdfWriter.GetImportedPage(pdfReader, pageNumber);

作为一个例子,您可以将previous code中的 OnOpenDocument 事件 PdfPageEventHelper 然后在的OnEndPage 事件时,可以使用 PdfWriter <的 DirectContentUnder 对象/ code>来将整个页面的当前页面的下方。

As an example, you can place the previous code in the OnOpenDocument event of a PdfPageEventHelper and then in the OnEndPage event you can use the DirectContentUnder object of the PdfWriter to place the entire page underneath your current page.

pdfWriter.DirectContentUnder.AddTemplate(importedPage, 0, 0);

这篇关于如何复制表单域PdfWriter不PdfCopy在iTextSharp的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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