Esempio n. 1
0
        static public void AddTextFieldsOnPage(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;

            IPXC_UndoRedoData urD       = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages.InsertPage(0, rc, out urD);
            PXC_Rect          textRC    = new PXC_Rect();

            textRC.top    = rc.top - 1.0 * 72.0;
            textRC.left   = 1.0 * 72.0;
            textRC.bottom = rc.top - 2.0 * 72.0;
            textRC.right  = rc.right - 1.0 * 72.0;

            //Ordinary text field
            IPXC_FormField firstTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC);

            firstTextBOX.SetValueText("Ordinary text field");
            Marshal.ReleaseComObject(firstTextBOX);

            //Read-only and locked text field with custom style
            textRC.top    = rc.top - 3.0 * 72.0;
            textRC.bottom = rc.top - 4.0 * 72.0;
            IPXC_FormField secondTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC);

            secondTextBOX.SetValueText("Read-only and locked text field with custom style");
            IAUX_Inst             auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_Annotation       annot   = secondTextBOX.Widget[0];
            IPXC_AnnotData_Widget WData   = (IPXC_AnnotData_Widget)annot.Data;
            IColor color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.9f, 0.9f, 0.6f);
            WData.FColor = color;
            color.SetRGB(0.6f, 0.9f, 0.9f);
            WData.SColor = color;
            PXC_AnnotBorder border = new PXC_AnnotBorder();

            border.nStyle       = PXC_AnnotBorderStyle.ABS_Dashed;
            border.DashArray    = new float[10];
            border.DashArray[0] = border.DashArray[1] = 16.0f; //Width of dashes
            border.nDashCount   = 2;                           //Number of dashes
            border.nWidth       = 5.0f;
            WData.set_Border(ref border);
            annot.Data = WData;
            secondTextBOX.SetFlags((uint)PXC_FormFieldFlag.FFF_ReadOnly, (uint)PXC_FormFieldFlag.FFF_ReadOnly);
            Marshal.ReleaseComObject(secondTextBOX);



            //90 degree orientation text field with multiline option enabled
            textRC.top    = rc.top - 5.0 * 72.0;
            textRC.bottom = rc.top - 7.0 * 72.0;
            IPXC_FormField thirdTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC);

            thirdTextBOX.SetFlags((uint)PXC_FormFieldFlag.TFF_MultiLine, (uint)PXC_FormFieldFlag.TFF_MultiLine);
            thirdTextBOX.SetValueText("90 degree orientation text field with multiline option enabled");
            annot = thirdTextBOX.Widget[0];
            WData = (IPXC_AnnotData_Widget)annot.Data;
            WData.ContentRotation = 90;
            annot.Data            = WData;
            Marshal.ReleaseComObject(thirdTextBOX);

            //Time formatted text field with custom JS that gives current time
            textRC.top    = rc.top - 8.0 * 72.0;
            textRC.bottom = rc.top - 9.0 * 72.0;
            IPXC_FormField fourthTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC);

            annot        = fourthTextBOX.Widget[0];
            annot.Flags |= (uint)PXC_SignDocumentFlags.Sign_TX_Date;
            IPXC_ActionsList actionsList = Parent.m_CurDoc.CreateActionsList();

            //Set script to ActionList
            actionsList.AddJavaScript("var now = new Date()\n" +
                                      "this.getField(\"Text4\").value = now.getHours() + \":\" + now.getMinutes() ");
            fourthTextBOX.Actions[PXC_TriggerType.Trigger_Format] = actionsList;
            Marshal.ReleaseComObject(fourthTextBOX);
            Marshal.ReleaseComObject(firstPage);
            Marshal.ReleaseComObject(pages);
        }