Esempio n. 1
0
        static public void AddCheckBoxFormFields(Form1 Parent)
        {
            int index = 1;
            //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x);
            CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) =>
            {
                string sFieldName = "";
                uint   i          = 0;
                do
                {
                    sFieldName = fName + inx;
                    IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName);
                    if (ff == null)
                    {
                        break;
                    }
                    inx++;
                    i++;
                }while (i <= Doc.AcroForm.FieldsCount);
                inx++;
                return(sFieldName);
            };

            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            PXC_Rect rc = new PXC_Rect();

            rc.top   = 800;
            rc.right = 600;

            //Adding uncheked checkbox
            IPXC_UndoRedoData urD   = null;
            IPXC_Pages        pages = Parent.m_CurDoc.Pages;
            IPXC_Page         Page  = pages.InsertPage(0, rc, out urD);
            PXC_Rect          rcPB  = new PXC_Rect();

            rcPB.left   = 3.2 * 72.0;
            rcPB.right  = rcPB.left + 0.5 * 72.0;
            rcPB.top    = rc.top - 0.2 * 72.0;
            rcPB.bottom = rcPB.top - 0.5 * 72.0;             //top is greater then bottom (PDF Coordinate System)
            IPXC_FormField checkBoxUnch = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "CheckBox", ref index), PXC_FormFieldType.FFT_CheckBox, 0, ref rcPB);

            Marshal.ReleaseComObject(checkBoxUnch);

            //Adding cheked checkbox
            rcPB.right = rc.right - 3.2 * 72.0;
            rcPB.left  = rcPB.right - 0.5 * 72.0;
            IPXC_FormField        checkBoxCh = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "CheckBox", ref index), PXC_FormFieldType.FFT_CheckBox, 0, ref rcPB);
            IPXC_Annotation       annot      = checkBoxCh.Widget[0];
            IPXC_AnnotData_Widget widget     = (IPXC_AnnotData_Widget)annot.Data;

            checkBoxCh.CheckWidget((uint)checkBoxCh.GetWidgetIndex(annot), true);
            Marshal.ReleaseComObject(checkBoxCh);
            Marshal.ReleaseComObject(Page);
            Marshal.ReleaseComObject(pages);
        }