简体   繁体   English

itextsharp合并具有形式的pdf文件

[英]itextsharp merge pdf files having forms

I'm trying to use itextsharp to merge two PDF files (version 7), both having form fields. 我正在尝试使用itextsharp合并两个具有表单字段的两个PDF文件(版本7)。 When I run the code I get this error message: "Cannot handle iref streams. The current implementation of PDFsharp cannot handle this PDF feature introduced with Acrobat 6." 当我运行代码时,出现以下错误消息:“无法处理iref流。PDFsharp的当前实现无法处理Acrobat 6引入的PDF功能。” I tried different approaches but in my last I got the PDFs but instead of the original file contents, I got a file with the following info: 我尝试了不同的方法,但是在最后一次获得PDF时,我得到了包含以下信息的文件,而不是原始文件的内容:

     Please wait... If this message is not eventually replaced by the proper contents of the document, your PDF viewer may not be able to
 display this type of document. You can upgrade to the latest version
 of Adobe Reader for Windows®, Mac, or Linux® by visiting
 http://www.adobe.com/go/reader_download. For more assistance with
 Adobe Reader visit http://www.adobe.com/go/acrreader. Windows is
 either a registered trademark or a trademark of Microsoft Corporation
 in the United States and/or other countries. Mac is a trademark of
 Apple Inc., registered in the United States and other countries. Linux
 is the registered trademark of Linus Torvalds in the U.S. and other
 countries.

Can anyone help me and post some working code method to concatenate two Pdfs of this kind. 谁能帮助我并发布一些有效的代码方法来连接两个这种Pdf。 Thank you in advance. 先感谢您。

You either have forms based on AcroForm technology. 您要么具有基于AcroForm技术的表单。 In this case the fields are described using PDF objects such as field dictionaries, widget annotation dictionaries, etc... These forms can easily be merged, regardless of the fact if they are PDF 1.7, 1.6,... 在这种情况下,使用PDF对象(例如字段字典,窗口小部件注释字典等)来描述字段。这些形式可以轻松合并,无论它们是PDF 1.7、1.6,...还是事实。

You can also have forms based on the XML Forms Architecture (XFA) in which case the PDF acts as a contained for an XML stream. 您还可以具有基于XML表单体系结构(XFA)的表单,在这种情况下,PDF充当XML流的包含对象。 Usually such a form starts from an XML schema. 通常,这种形式是从XML模式开始的。

Based on the "your PDF viewer may not be able to display this type of document" message, it seems that you are dealing with XFA forms. 根据“您的PDF查看器可能无法显示这种类型的文档”消息,看来您正在处理XFA表单。

If you want to merge pure XFA forms, you have the following options: 如果要合并纯XFA表单,则可以使用以下选项:

  1. If the forms have the same schema, you extract the XML data from both forms, merge the XML data and fill an empty form with the merged data. 如果表单具有相同的架构,则可以从两个表单中提取XML数据,合并XML数据,并用合并的数据填充空白表单。 This assumes that you know the XML schema and that you know how to merge the XML data. 这假设您知道XML模式,并且知道如何合并XML数据。
  2. If the forms don't have the same schema, it will be extremely difficult (if not impossible) to merge the forms and keep the forms interactive: you'd need to create a new schema for the data and basically create a new form from scratch. 如果表单不具有相同的架构,将很难合并(如果不是不可能的话)合并表单并使表单保持交互性:您需要为数据创建一个新的架构,并从根本上创建一个新的表单刮。
  3. You may be in luck if the forms are "hybrid". 如果表格“混合”,您可能会很幸运。 That is: if they contain a description of the form using both technologies next to each other. 也就是说:如果它们同时使用两种技术包含对表单的描述。 In that case, throw away the XFA part of the form, keep the AcroForm part and merge the AcroForm forms. 在这种情况下,请丢弃表单的XFA部分,保留AcroForm部分并合并AcroForm表单。
  4. Finally, you could flatten the forms first (using our closed source XFA worker) and then merge the flattened PDFs. 最后,您可以先展平表单(使用我们的封闭源代码XFA工作器),然后合并展平的PDF。 The end result will no longer be a form. 最终结果将不再是表格。

Bottom line: the answer to your question ranges from "you're trying to do something that is impossible if not done by a human" (merging two XFA forms based on a different XML schema) to "you're trying to do something that is really easy" (merging two AcroForm forms, possibly after removing the XFA counter-part). 底线:您的问题的答案范围从“您试图做一些如果没有人做就不可能做的事情” (合并基于不同XML架构的两个XFA表单)到“您正在尝试做一些事情”非常简单” (合并两个AcroForm表单,可能在删除XFA对应部分之后)。

A definitive answer can't be given as you are not giving us any details on the nature of the forms. 由于您没有向我们提供有关表格性质的任何详细信息,因此无法给出确切的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM