什么是copyAcroForm的替代品? [英] Whats the alternative to copyAcroForm?

查看:129
本文介绍了什么是copyAcroForm的替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前正在将代码库从iText 2.1.7移植到iText 5.5.0(是的,我知道..我们花了一些时间;-). 好吧..现在",copyAcroForm已经取代了渡渡鸟,我正在努力寻找该代码的替代方案:

We are currently porting our code base from iText 2.1.7 to iText 5.5.0 (yeah I know.. we had a little longer ;-). Well.. "now" that copyAcroForm has gone the way of the Dodo, I'm struggling to find an alternative to this code:

  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();

但是还没有真正找到任何东西.我读了4.34或以上的变更日志,因此我显然应该使用PdfCopy.addDocument().我尝试了一下,然后注释掉了其他代码,例如:

but haven't really found anything. I read in the changelog of 4.34 or so that I apparently should use PdfCopy.addDocument(). I tried that and commented out the other code, such as this:

  ...
  PdfReader reader = new PdfReader(generationReader);
  reader.consolidateNamedDestinations();
  subjobWriter.addDocument(reader);
  subjobWriter.freeReader(reader);
  subjobWriter.setOutlines(SimpleBookmark.getBookmark(reader));
  ...

但是那也没有帮助.

问题在于,除了表格(及其字段和内容)外,原始PDF的所有内容都被复制了,或者看起来整个表格已经变平了.

The problem is, that everything from the original PDF is copied EXCEPT the form (and its fields and content), or rather, it looks like the whole form has been flattened instead.

由于所有示例我都可以找到不再使用的copyAcroForm()或已弃用的PdfCopyFields类,itextpdf.com和"iText in Action,第二版"中的所有示例都使用copyAcroForm()同样,我不知道如何解决这个问题.有人知道吗?

Since all the samples I could find either used copyAcroForm() which doesn't exist anymore or the PdfCopyFields class which is deprecated and all the samples at itextpdf.com and the "iText in Action, 2nd edition" use copyAcroForm() as well, I'm at loss as to how to solve this. Any idea anyone?

Rog

推荐答案

请查看 示例:

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();

您添加了该行吗?

这篇关于什么是copyAcroForm的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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