最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - iText7 pdfXFA error AbstractITextEvent is only for internal usage - Stack Overflow

programmeradmin2浏览0评论

I am evaluating the iText7 pdfXFA add-on to flatten a Dynamic XFA PDF form. I've created a simple C# Console application and used the C# code example at as a guide.

static void Main(string[] args)
{
    string importFilePath = "Input.pdf";
    string exportFilePath = "Output.pdf";

    if (File.Exists(exportFilePath))
    {
        File.Delete(exportFilePath);
    }

    XFAFlattenerProperties flattenerProperties = new XFAFlattenerProperties()
        .SetPdfVersion(XFAFlattenerProperties.PDF_1_7)
        .CreateXmpMetaData()
        .SetTagged()
        .SetMetaData(
                new MetaData()
                    .SetAuthor("iText Samples")
                    .SetLanguage("EN")
                    .SetSubject("Showing off our flattening skills")
                    .SetTitle("Flattened XFA"));

    XFAFlattener xfaf = new XFAFlattener()
        .SetFlattenerProperties(flattenerProperties);

    xfaf.Flatten(
        new FileStream(importFilePath, FileMode.Open, FileAccess.Read), 
        new FileStream(exportFilePath, FileMode.Create, FileAccess.Write));
}

However, I'm getting the error "AbstractITextEvent is only for internal usage." when it reaches the Flatten() method. The stack trace looks like this:

at iText.Commons.Actions.AbstractITextEvent..ctor()
at iText.Commons.Actions.AbstractProductITextEvent..ctor(ProductData productData)
at iText.Commons.Actions.AbstractProductProcessITextEvent..ctor(SequenceId sequenceId, ProductData productData, IMetaInfo metaInfo, EventConfirmationType confirmationType)
at iTextSharp.tool.xml.actions.PdfXfaProductEvent..ctor(SequenceId sequenceId, IMetaInfo metaInfo, String eventType)
at iTextSharp.tool.xml.actions.PdfXfaProductEvent.CreateFlattenXfaEvent(SequenceId sequenceId, IMetaInfo metaInfo)
at iTextSharp.tool.xml.xtra.xfa.XFAFlattener.Initialize(Stream pdfOutputStream, String oldProducer)
at iTextSharp.tool.xml.xtra.xfa.XFAFlattener.Flatten(Stream xfaInputStream, Stream pdfOutputStream)
at iText7PdfXfaConsole.Program.Main(String[] args) in E:\DevProjects\iText7PdfXfaConsole\Program.cs:line 37

I am using .NET Framework 4.8 in my Console application as that is what we are currently using in our main application. Any recommendations on what I can do to get this to work?

The online demo at seems to do exactly what we require so I'm hoping we can leverage this library in our application.

发布评论

评论列表(0)

  1. 暂无评论