Detect dynamic XFA with iText

一世执手 提交于 2019-12-06 01:25:11

iText is free as in free speech, not free as in free beer. Read http://lowagie.com/bumodels for more info about the business models we've tried in order to avoid switching from the MPL/LGPL to the AGPL.

Q1: making dynamic XFA forms read-only

That's a no-brainer with the most recent version of iText, but not supported in the obsolete version you're using. Please read http://lowagie.com/itext2 to find out why you shouldn't use iText 4.2.0 (which as far as I know isn't even an official release; and I know, because I'm responsible for every single iText release). Maybe you're talking about iTextSharp.

Q2: flattening dynamic XFA forms

If you want to flatten a dynamic XFA form, you have two options: either use Adobe LiveCycle ES (which will cost you an arm and a leg), or use iText's XFA Worker (which is a much less expensive closed source product built on top of the F/OSS iText). Given the cost and the number of man hours that went into this product, I don't think you'll find a solution that is free as in free beer. I for one don't know of any such product.

Q3: how to find out if an XFA form is dynamic

This is explained in my book, "iText in Action - Second Edition." You already have half of the solution. Condition 1: isXfaPresent() needs to return true. Condition 2: getFields() needs to have an empty key set. See the method readFieldnames() in this example.

To add to Bruno's answer and to provide C# example code:

PdfReader reader = new PdfReader(filePath);
XfaForm xfa = new XfaForm(reader);

//Check if PDF file contains Dynamic XFA data
if (xfa != null && xfa.XfaPresent && xfa.Reader.AcroFields.Fields.Keys.Count == 0)
{
   MessageBox.Show("This PDF contains Dynamic XFA data.");
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!