com.itextpdf.kernel.PdfException: StructureElement shall contain parent object exception is thrown when form.flattenFields() method is called in iText

huangapple go评论142阅读模式
英文:

com.itextpdf.kernel.PdfException: StructureElement shall contain parent object exception is thrown when form.flattenFields() method is called in iText

问题

我有一个需求,通过AEM生成模板,然后使用iText将数据填充到这些字段中。

数据已成功映射到模板中的文本字段。之后,在尝试展平PDF时,我收到以下异常:

com.itextpdf.kernel.PdfException:StructureElement应包含父对象。
在com.itextpdf.kernel.pdf.tagutils.TagTreePointer.java的718行。
在com.itextpdf.kernel.pdf.tagutils.TagStructureContext.java的342行中删除Annotation标签。
在com.itextpdf.forms.PdfAcroForm.java的658行中展平字段。

该模板仅包含所有文本字段和一些用于根据内容隐藏/显示某些字段的JavaScript逻辑。我删除了JavaScript逻辑(iText无论如何都无法识别此逻辑),并测试以查看展平是否有效,但未成功。

我怀疑通过AEM生成的模板,我正在从.xdp文件创建.pdf文件引起了此问题。我只是在AEM的LiveCycle设计师中使用“另存为”选项来创建它。是否有其他建议以创建准确的.pdf文件,以便iText在展平时不会引发异常?

英文:

I have a requirement where templates are generated through AEM and then iText consumes it to populate data on to those fields.

Data is mapped successfully on to the text fields in the template. After that, while trying to flatten the pdf I receive below exception

com.itextpdf.kernel.PdfException: StructureElement shall contain parent object.
at com.itextpdf.kernel.pdf.tagutils.TagTreePointer.setCurrentStructElem(TagTreePointer.java:718) ~[kernel-7.1.12.jar:?]
at com.itextpdf.kernel.pdf.tagutils.TagStructureContext.removeAnnotationTag(TagStructureContext.java:342) ~[kernel-7.1.12.jar:?]
at com.itextpdf.forms.PdfAcroForm.flattenFields(PdfAcroForm.java:658) ~[forms-7.1.12.jar:?]

The template has all text fields only and some javascript logic to hide/show some fields if empty. I removed javascript logic(iText doesnt recognize this logic anyways) and tested to see if flatten works and it didn't.

I doubt if my template generated through AEM where I am creating .pdf file from .xdp file caused this issue. I just used save as option in LiveCycle designer of AEM to create it. Any other suggestion to create accurate .pdf file so iText doesn't throw exception on flattening?

答案1

得分: 1

我可以确认表单字段结构标签的问题是根本原因。而且在AEM 6.5.15版本中,结构标签基本上配置不正确,而使用AEM 6.5.11或更低版本创建的.PDF文件模板具有正确的结构标签。

已经与Adobe开启了一个关于此问题的工单。谢谢。

英文:

I can confirm that issue with Structure tags of form fields is the root cause for this. And structure tags are basically not configured correctly in AEM 6.5.15 version, whereas a .PDF file template created using AEM 6.5.11 or below has right structure tags.

Have an open ticket with Adobe to discuss this issue. Thanks

huangapple
  • 本文由 发表于 2023年7月20日 22:37:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730992.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定