XFA Creating Multiple Instances of a Page with iTextSharp

551 views Asked by At

Looking at the USCIS form N-400, you can see that in Part 9 has two buttons, Add Children and Go to continuation page Looking at the XML/JS backing those buttons you get this node for the corresponding field:

<event activity="click" name="event__click">
    <script contentType="application/x-javascript">
        _KidsContPage.addInstance(1);
        xfa.form.recalculate(1);
        xfa.host.pageDown( );
    </script>
</event>

This is used to add the automatically hidden page to the form in case the user has more than 8 children. My question is using iTextSharp, or perhaps some other method, how do I create this new instance of the page? If you notice you can make multiple copies of this additional children page, if, somehow, you happen to have more than 25 kids, so not getting side-tracked by the unlikelihood of that possibility, I need to know how to create multiples of such a page...

This is what I have so far:

PdfAction cloneAction = PdfAction
    .JavaScript(ClonePage("KidsContPage"), stamper.Writer);
stamper.Writer.AddJavaScript(cloneAction);

I've also tried with SetOpenAction

stamper.Writer.SetOpenAction(cloneAction);


    private string ClonePage(string formName)
    {
        return @"
if (xfa.host.name != 'XFAPresentationAgent') {
    $._" + formName + @".addInstance(1);
    if (xfa.host.version < 8) {
        xfa.form.recalculate(1);
    }
}";
    }

I know that my ClonePage() code is being run, because I see the alert when I tested it earlier, the problem is in the javascript or perhaps I somehow need to run it at server or who knows what I need to do. I opened the XFA PDF in LiveCycle and that's the JS that it's putting out for it, I must be missing something small somewhere...and it works fine in LiveCycle. Please help.

0

There are 0 answers