Itext 有什么办法可以替代复制形式?

Itext 有什么办法可以替代复制形式?,itext,Itext,我们目前正在将代码库从iText 2.1.7移植到iText 5.5.0(是的,我知道..我们有一点时间;-)。 好。。“现在”copyAcroForm已经走上了Dodo的道路,我正在努力寻找替代此代码的方法: File outputFile = new File... Document document = new Document(); FileOutputStream fos = new FileOutputStream(outputFile); PdfCopy subjo

我们目前正在将代码库从iText 2.1.7移植到iText 5.5.0(是的,我知道..我们有一点时间;-)。 好。。“现在”copyAcroForm已经走上了Dodo的道路,我正在努力寻找替代此代码的方法:

  File outputFile = new File...
  Document document = new Document();
  FileOutputStream fos = new FileOutputStream(outputFile);
  PdfCopy subjobWriter = new PdfCopy(document, fos);
  document.open();
  PdfReader reader = new PdfReader(generationReader);
  for (int i=1; i<=reader.getNumberOfPages(); i++) {
    PdfImportedPage page = subjobWriter.getImportedPage(reader, i);
    subjobWriter.addPage(page);
  }
  PRAcroForm form = reader.getAcroForm();
  if (form != null)
    subjobWriter.copyAcroForm(reader);
  subjobWriter.freeReader(reader);
  reader.close();
  subjobWriter.close();
  document.close();
  fos.close();
但这也没用

问题是,除了表单(及其字段和内容)之外,原始PDF中的所有内容都被复制了,或者更确切地说,看起来整个表单都被展平了

由于我能找到的所有示例要么是已不存在的已用copyAcroForm(),要么是已弃用的PdfCopyFields类,而itextpdf.com上的所有示例和“iText in Action,第二版”也都使用copyAcroForm(),因此我不知道如何解决这个问题。有人知道吗

Rog

请看一看示例:

有一句话特别重要:

copy.setMergeFields();

你加上那句话了吗?

啊,谢谢你,布鲁诺。。是的,我曾经加过,但显然位置不对。您的样品很好用,非常感谢!是否有计划推出第三版iText(我很乐意购买:-)?是和否。我正在写一系列的书,但不是为出版商写的。它们将在LeanPub上免费提供:我从一本关于低级PDF的书开始,但正如您所看到的,我已经在收集有关高级PDF创建和操作的书籍的示例。这个视频教程已经给你一个印象,你可以期待:整洁!我会看看他们。。。谢谢你帮助我。最后一个快速问题是:我发现XmpWriter.addrdfddescription()已被弃用。还有什么替代方案?是否有一个页面可以查看不推荐的方法的替代方案?或者我可以提出一个建议并添加一个Javadoc描述(如果可能的话)来链接到Altentives,或者,如果是一个小的更改,则显示Javadoc中已经发生的更改?旧的XMP功能被一个完整的包(com.textpf.XMP)所取代,并且除了测试套件中的测试之外(遵循Maven结构,您会发现测试),现在还没有任何例子。我想用这个答案来结束另一个重复的问题,但似乎,虽然我的答案是正确的,但它既没有被接受,也没有被投票支持。因此,我不能用它来结束另一个重复的问题。你能接受这个答案吗?
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileOutputStream(filename));
copy.setMergeFields();
document.open();
for (PdfReader reader : readers) {
    copy.addDocument(reader);
}
document.close();
for (PdfReader reader : readers) {
    reader.close();
}
copy.setMergeFields();