问题描述
我假设我需要展平XFA表单,以便在使用Nuance的CSDK的应用程序的UI上正确显示。当我现在处理它时,我收到一条通用消息Please Wait ....如果此消息最终没有被替换..。
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 Forms Architecture(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表单通常由单页PDF(带有请等待......消息)在查看器中显示不理解XFA。文档的实际内容存储为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工作人员完成:
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文件以及示例:
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
但是:由于太多的开发人员在没有购买商业许可的情况下在商业环境中使用AGPL版本的iTextSharp,我们决定不开源XFA Worker。您可以获得试用期的许可证密钥,但它是基于商业版iTextSharp构建的商业产品。如果您从iText Software购买许可证,XFA Worker只能在生产中使用。对于iTextSharp也是如此,但是对于iTextSharp,如果您不购买商业许可证,则没有许可证密钥可以阻止使用。对于iTextSharp,我们依靠诚实。对于XFA工作者,我们采取了一些预防措施; - )
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表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!