如何使用 iTextSharp 展平 XFA PDF 表单? [英] How can I flatten a XFA PDF Form using iTextSharp?

查看:20
本文介绍了如何使用 iTextSharp 展平 XFA PDF 表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设我需要展平 XFA 表单,以便在使用 Nuance 的 CSDK 的应用程序的 UI 上正确显示.当我现在处理它时,我收到一条通用消息请稍候......如果此消息最终没有被替换......".

I assume I need to flatten a XFA form in order to display properly on the UI of an application that uses Nuance's CSDK. When I process it now I get a generic message "Please Wait.... If this message is not eventually replaced..".

正在寻找一些示例 iTextSharp 代码来执行此操作.

Looking for some sample iTextSharp code to do this.

推荐答案

您没有插入代码示例来展示您当前如何展平 XFA 表单.我假设您的代码如下所示:

You didn't insert a code sample to show how you are currently flattening the XFA form. I assume your code looks like this:

var reader = new PdfReader(existingFileStream);
var stamper = new PdfStamper(reader, newFileStream);
var form = stamper.AcroFields;
var fieldKeys = form.Fields.Keys;
foreach (string fieldKey in fieldKeys) {
    form.SetField(fieldKey, "X");
}
stamper.FormFlattening = true;
stamper.Close();
reader.Close();

当尝试将基于 AcroForm 技术的表单扁平化时,此代码将起作用,但它不能用于基于 XML 表单架构 (XFA) 的表单!

This code will work when trying to flatten forms based on AcroForm technology, but it can't be used for forms based on the XML Forms Architecture (XFA)!

动态 XFA 表单通常包含在不理解 XFA 的查看器中显示的单页 PDF(带有请稍候..."消息的页面).文档的实际内容存储为 XML 文件.

A dynamic XFA form usually consists of a single page PDF (the one with the "Please wait..." message) that is shown in viewer that do not understand XFA. The actual content of the document is stored as an XML file.

将 XFA 表单扁平化为普通 PDF 的过程需要您解析 XML 并将 XML 语法转换为 PDF 语法.这可以使用 iText 的 XFA Worker 完成:http://itextpdf.com/product/xfa_worker

The process of flattening an XFA form to an ordinary PDF requires that you parse the XML and convert the XML syntax into PDF syntax. This can be done using iText's XFA Worker: http://itextpdf.com/product/xfa_worker

假设您在内存中有一个文件 (ms),其中包含一个已填写的 XFA 表单,那么您可以使用以下代码来展平该表单:

Suppose that you have a file in memory (ms) that consists of an XFA form that is filled out, then you can use the following code to flatten that form:

Document document = new Document();
PdfWriter writer =
    PdfWriter.GetInstance(document, new FileStream(dest, FileMode.Create));
XFAFlattener xfaf = new XFAFlattener(document, writer);
ms.Position = 0;
xfaf.Flatten(new PdfReader(ms));
document.Close();

您可以下载包含 XFA Worker DLL 的 zip 文件以及此处的示例:http://itextsupport.com/download/xfa-net.zip

You can download a zip file containing the DLLs for XFA Worker as well as an example here: http://itextsupport.com/download/xfa-net.zip

然而:由于太多开发人员在没有购买商业许可证的情况下在商业环境中使用 iTextSharp 的 AGPL 版本,我们决定不开源 XFA Worker.您可以获得试用期的许可证密钥,但它是建立在 iTextSharp 商业版本之上的商业产品.如果您从 iText Software 购买许可证,XFA Worker 只能用于生产.iTextSharp 也是如此,但是对于 iTextSharp,如果您不购买商业许可证,则没有许可证密钥可以阻止使用.对于 iTextSharp,我们依靠诚实.对于 XFA Worker,我们采取了一些预防措施 ;-)

However: as too many developers are using the AGPL version of iTextSharp in a commercial context without buying a commercial license, we have decided not to open source XFA Worker. You can get a license key for a trial period, but it is a commercial product built on top of the commercial version of iTextSharp. XFA Worker can only be used in production if you purchase a license from iText Software. This is also true for iTextSharp, but with iTextSharp, there is no license key that prevents the use if you do not buy a commercial license. For iTextSharp, we count on honesty. For XFA Worker, we took some precautions ;-)

这篇关于如何使用 iTextSharp 展平 XFA PDF 表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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