iTextSharp get contents from PDF with XFA form

836 views Asked by At

I would like to get some help to perform the following task: I have a PDF template with XFA form, created with Adobe Lifecycle, containning an Header with fillable fields, a footer also with fillable fields and a textbox field in the middle. I need to create a new PDF from scratch where I have to programmatically get the header of the template after been filled, add some new contents after the header (WITHOUT using any form field) and in the end we have to get the footer also from the already filled PDF.

I tried something like the following but I couldn't get the elements by name/id:

 public void ReadPDFformDataPageWise(string inputFile)
    {
        PdfReader reader = new PdfReader(inputFile);
        AcroFields form = reader.AcroFields;
        try
        {
            for (int page = 1; page <= reader.NumberOfPages; page++)
            {
                foreach (string key in form.Fields.Keys)
                {
                    switch (form.GetFieldType(key))
                    {
                        case AcroFields.FIELD_TYPE_CHECKBOX:
                            //Create Checkbox
                        case AcroFields.FIELD_TYPE_COMBO:
                        //Create Combo Box
                        case AcroFields.FIELD_TYPE_LIST:
                        //Create List
                        case AcroFields.FIELD_TYPE_RADIOBUTTON:
                        //Create Radio button
                        case AcroFields.FIELD_TYPE_NONE:
                        case AcroFields.FIELD_TYPE_PUSHBUTTON:
                        //Create Submit Button
                        case AcroFields.FIELD_TYPE_SIGNATURE:
                        //Create Signature
                        case AcroFields.FIELD_TYPE_TEXT:
                            //Create textbox/Qs header
                            int fileType = form.GetFieldType(key);
                            string fieldValue = form.GetField(key);
                            float[] a = form.GetFieldPositions(key);
                            string translatedFileName = form.GetTranslatedFieldName(key);
                           AcroFields.Item test=  form.GetFieldItem(key);

                            break;
                    }
                }
            }
        }
        catch
        {
        }
        finally
        {
            reader.Close();
        }
    }

I would like to have something like:

ReadPDFformDataPageWise(string inputFile, string elementToGet)

The new PDF contents can have several pages and is just readonly (no XFA elements). Can anyone help me on this task? Can we get parts of a PDF with XFA forms after been filled by name/element?

0

There are 0 answers