Esempio n. 1
0
        static public int AddActionNamed(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Bookmark bookmark = null;

            if (Parent.SelectedBookmarkNode == null)
            {
                bookmark = Parent.m_CurDoc.BookmarkRoot.AddNewChild(true);
            }
            else
            {
                bookmark = Parent.SelectedBookmarkNode.m_Bookmark.AddNewSibling(false);
            }

            IPXS_Inst         pxsInst     = Parent.m_pxcInst.GetExtension("PXS");
            uint              atomNamed   = pxsInst.StrToAtom("Named");
            IPXC_Action_Named actionNamed = Parent.m_pxcInst.GetActionHandler(atomNamed).CreateEmptyAction(atomNamed, Parent.m_CurDoc) as IPXC_Action_Named;

            actionNamed.CmdName = "NextPage";
            IPXC_ActionsList aList = Parent.m_CurDoc.CreateActionsList();

            bookmark.Title = "Execute Command Action";
            bookmark.Style = PXC_BookmarkStyle.BookmarkFont_Normal;
            aList.Insert(0, actionNamed);
            bookmark.Actions = aList;

            return((int)Form1.eFormUpdateFlags.efuf_Bookmarks);
        }
Esempio n. 2
0
        static public int AddActionsGoToE(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Bookmark bookmark = null;

            if (Parent.SelectedBookmarkNode == null)
            {
                bookmark = Parent.m_CurDoc.BookmarkRoot.AddNewChild(true);
            }
            else
            {
                bookmark = Parent.SelectedBookmarkNode.m_Bookmark.AddNewSibling(false);
            }

            IPXS_Inst       pxsInst     = Parent.m_pxcInst.GetExtension("PXS");
            uint            atomGoToE   = pxsInst.StrToAtom("GoToE");
            IPXC_NameTree   attachments = Parent.m_CurDoc.GetNameTree("EmbeddedFiles");
            IPXS_PDFVariant var         = null;

            try
            {
                var = attachments.Lookup("FeatureChartEU.pdf");
            }
            catch (Exception)
            {
                string                  sFilePath = System.Environment.CurrentDirectory + "\\Documents\\FeatureChartEU.pdf";
                IPXC_FileSpec           fileSpec  = Parent.m_CurDoc.CreateEmbeddFile(sFilePath);
                IPXC_EmbeddedFileStream EFS       = fileSpec.EmbeddedFile;
                EFS.UpdateFromFile2(sFilePath);
                var = fileSpec.PDFObject;
            }

            attachments.Add("FeatureChartEU.pdf", var);

            IPXC_Action_Goto actionGoToE = Parent.m_pxcInst.GetActionHandler(atomGoToE).CreateEmptyAction(atomGoToE, Parent.m_CurDoc) as IPXC_Action_Goto;

            IPXC_GoToETargetPath targetPath = actionGoToE.TargetPath;
            IPXC_GoToETargetItem targetItem = targetPath.InsertNew();

            targetItem.FileName   = "FeatureChartEU.pdf";
            targetItem            = targetPath.InsertNew();
            targetItem.FileName   = "MyStamps.pdf";
            targetItem            = targetPath.InsertNew();
            targetItem.AnnotIndex = 0;
            targetItem.PageNumber = 0;

            IPXC_ActionsList aList = Parent.m_CurDoc.CreateActionsList();

            bookmark.Title = "GoToE Action";
            bookmark.Style = PXC_BookmarkStyle.BookmarkFont_Normal;
            aList.Insert(0, actionGoToE);
            bookmark.Actions = aList;

            Marshal.ReleaseComObject(attachments);

            return((int)Form1.eFormUpdateFlags.efuf_Bookmarks | (int)Form1.eFormUpdateFlags.efuf_Attachments);
        }
Esempio n. 3
0
        static public void AddStandardStampByID(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Pages         pages        = Parent.m_CurDoc.Pages;
            IPXC_Page          firstPage    = pages[0];
            PXC_Rect           rcPB         = firstPage.get_Box(PXC_BoxType.PBox_PageBox);
            IPXC_StampsManager stampManager = Parent.m_pxcInst.StampsManager;
            IPXC_StampInfo     si           = stampManager.FindStamp("Draft");
            //Creating stamp annotation
            IPXS_Inst pSInt   = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            uint      nStamp  = pSInt.StrToAtom("Stamp");
            double    nHeight = 0;
            double    nWidth  = 0;

            si.GetSize(out nWidth, out nHeight);
            PXC_Rect rc;

            rc.left   = rcPB.left - nWidth / 2.0 + nHeight / 2.0;
            rc.right  = rcPB.left + nWidth / 2.0 + nHeight / 2.0;
            rc.top    = rcPB.top;
            rc.bottom = rc.top - nWidth;
            IPXC_Annotation      annot     = firstPage.InsertNewAnnot(nStamp, ref rc, 0);
            IPXC_AnnotData_Stamp stampData = (IPXC_AnnotData_Stamp)annot.Data;

            stampData.Rotation = 90;
            stampData.SetStampName(si.ID);
            annot.Data = stampData;
            Marshal.ReleaseComObject(firstPage);
            Marshal.ReleaseComObject(pages);
        }
        static public int ReadSignatureInfoFromStructure(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.OpenDocFromStringPath(Parent);
            }
            IPXS_Inst pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            //Getting structure document
            IPXS_Document structDoc = Parent.m_CurDoc.CosDocument;

            //Locking document for read
            structDoc.LockDocument();
            //Getting Pages dictionary
            IPXS_PDFVariant pagesDict = structDoc.Root.Dict_Get("Pages");
            //Getting pages array dictionary
            IPXS_PDFVariant kidsDict = pagesDict.Dict_Get("Kids");

            //Getting running through pagess
            for (uint p = 0; p < kidsDict.Count; p++)
            {
                IPXS_PDFVariant pageDict = kidsDict[p];
                //Getting annotations dictionary
                IPXS_PDFVariant annotsDict = pageDict.Dict_Get("Annots");
                for (uint i = 0; i < annotsDict.Count; i++)
                {
                    //Getting annotation by index
                    IPXS_PDFVariant annotItem = annotsDict[i];
                    //Getting subtype
                    IPXS_PDFVariant subtypeDict = annotItem.Dict_Get("Subtype");
                    string          sName       = subtypeDict.GetName();
                    if (sName != "Widget")
                    {
                        continue;
                    }
                    //Getting FT node
                    IPXS_PDFVariant ftDict = annotItem.Dict_Get("FT");
                    string          sFT    = ftDict.GetName();
                    if (sFT != "Sig")
                    {
                        continue;
                    }
                    //If it is a signature then getting the V node with it's info
                    IPXS_PDFVariant vDict = annotItem.Dict_Get("V");
                    //Getting Reason dict
                    IPXS_PDFVariant reasonDict = vDict.Dict_Get("Reason");
                    string          sReason    = reasonDict.GetString();
                    //Getting ContactInfo
                    IPXS_PDFVariant contactInfoDict = vDict.Dict_Get("ContactInfo");
                    string          sContactInfo    = contactInfoDict.GetString();
                    System.Windows.Forms.MessageBox.Show(sReason + "\n" + sContactInfo);
                }
            }

            //Unlocking the document, since we've finished all of the work with it
            structDoc.UnlockDocument();


            return((int)Form1.eFormUpdateFlags.efuf_None);
        }
        static public int AddTextAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Text annotation atom for the InsertNewAnnot method
            uint nText = pxsInst.StrToAtom("Text");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 250;
            rcOut.right  = nCX - 150;
            rcOut.top    = nCY + 300;
            IPXC_Annotation     annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_Text aData = annot.Data as IPXC_AnnotData_Text;

            aData.Contents = "Text Annotation 1.";
            aData.Title    = "Text Annotation 1";
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.8f, 0.8f);
            aData.Color   = color;
            aData.Opacity = 0.5f;
            annot.Data    = aData;

            rcOut.bottom  -= 100;
            rcOut.top     -= 100;
            annot          = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData          = annot.Data as IPXC_AnnotData_Text;
            aData.Contents = "Text Annotation 2.";
            aData.Title    = "Text Annotation 2";
            color          = auxInst.CreateColor(ColorType.ColorType_RGB);
            color.SetRGB(0.5f, 0.4f, 0.48f);
            aData.Color = color;
            annot.Data  = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
Esempio n. 6
0
        static public void ExportAllFieldsOnPage(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.OpenDocumentFromStream(Parent);
                Parent.UpdateControlsFromDocument(0);
                Parent.UpdatePreviewFromCurrentDocument();
            }
            //Getting current page
            IPXC_Pages pages = Parent.m_CurDoc.Pages;
            IPXC_Page  Page  = pages[Parent.CurrentPage];

            //Locking CosDocument for reading
            Parent.m_CurDoc.CosDocument.LockDocument();
            //Creating new array that will store the variants of the needed form fields
            IPXS_Inst       pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            IPXS_PDFVariant arrVar  = pxsInst.NewVar_Array(0, Parent.m_CurDoc.CosDocument);
            //Get AcroForm from Document
            IPXC_AcroForm acroForm = Parent.m_CurDoc.AcroForm;

            for (uint i = 0; i < acroForm.FieldsCount; i++)
            {
                IPXC_FormField field = acroForm.Field[i];
                if (field == null)
                {
                    continue;
                }
                arrVar.Arr_Insert(field.PDFObject);
                Marshal.ReleaseComObject(field);
            }
            Parent.m_CurDoc.CosDocument.UnlockDocument();

            Marshal.ReleaseComObject(Page);
            Marshal.ReleaseComObject(pages);
            if (arrVar.Count == 0)
            {
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter          = "FDF Documents (*.fdf)|*.fdf|XFDF Documents (*.xfdf)|*.xfdf|HTML Documents (*.html)|*.hrml|XML Documents (*.xml)|*.xml";
            sfd.FilterIndex     = 4;
            sfd.CheckPathExists = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                IAFS_Inst afsInst = (IAFS_Inst)Parent.m_pxcInst.GetExtension("AFS");
                IAFS_Name name    = afsInst.DefaultFileSys.StringToName(sfd.FileName);
                string    sExt    = Path.GetExtension(sfd.FileName).ToLower();
                sExt = sExt.TrimStart('.');
                acroForm.Export(name, sExt, arrVar, true, (uint)PXC_ExportFormFlags.FormExport_Default);
                Process.Start("explorer.exe", "/select, \"" + sfd.FileName + "\"");
            }
        }
Esempio n. 7
0
        static public int AddPopupAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Popup annotation atom for the InsertNewAnnot method
            uint nSquare = pxsInst.StrToAtom("Square");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 200;
            rcOut.right  = nCX + 200;
            rcOut.top    = nCY + 300;
            IPXC_Annotation             sqAnnot = page.InsertNewAnnot(nSquare, ref rcOut);
            IPXC_AnnotData_SquareCircle aSData  = sqAnnot.Data as IPXC_AnnotData_SquareCircle;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.8f, 0.8f);
            aSData.Color    = color;
            aSData.Title    = "Square annotation 1.";
            aSData.Contents = "Popup Annotation 1.";
            sqAnnot.Data    = aSData;

            //Getting Text annotation atom for the InsertNewAnnot method
            uint                 nText = pxsInst.StrToAtom("Popup");
            IPXC_Annotation      annot = page.InsertNewAnnot(nText, ref rcOut);
            IPXC_AnnotData_Popup aData = annot.Data as IPXC_AnnotData_Popup;

            aData.Opened = true;
            annot.Data   = aData;
            sqAnnot.SetPopup(annot);

            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
Esempio n. 8
0
        static public void AddRadioButtonsFormFields(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            PXC_Rect rc = new PXC_Rect();

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

            //Adding group with RadioButtons
            IPXS_Inst         pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            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.top    = rc.top - 0.35 * 72.0;
            rcPB.bottom = rcPB.top - 0.5 * 72.0;             //top is greater then bottom (PDF Coordinate System)
            rcPB.left   = 1.7 * 72.0;
            rcPB.right  = rcPB.left + 0.5 * 72.0;
            IPXC_FormField firstGroup = Parent.m_CurDoc.AcroForm.CreateField("RadioButton", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB);

            rcPB.left  = 2.3 * 72.0;
            rcPB.right = rcPB.left + 0.5 * 72.0;
            Parent.m_CurDoc.AcroForm.CreateField("RadioButton", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB);
            rcPB.left  = 2.9 * 72.0;
            rcPB.right = rcPB.left + 0.5 * 72.0;
            Parent.m_CurDoc.AcroForm.CreateField("RadioButton", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB);

            rcPB.right = rc.right - 1.5 * 72.0;
            rcPB.left  = rcPB.right - 0.5 * 72.0;
            IPXC_FormField secondGroup = Parent.m_CurDoc.AcroForm.CreateField("RadioButton1", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB);

            rcPB.top    = rcPB.top - 0.6 * 72.0;
            rcPB.bottom = rcPB.top - 0.5 * 72.0;
            Parent.m_CurDoc.AcroForm.CreateField("RadioButton1", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB);
            firstGroup.CheckWidget(1, true);
            secondGroup.CheckWidget(1, true);

            Marshal.ReleaseComObject(firstGroup);
            Marshal.ReleaseComObject(secondGroup);
            Marshal.ReleaseComObject(Page);
            Marshal.ReleaseComObject(pages);
        }
        static public int DrawSquareAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Pages pages   = Parent.m_CurDoc.Pages;
            IPXC_Page  page    = pages[0];
            PXC_Rect   rcPage  = page.get_Box(PXC_BoxType.PBox_PageBox);
            IPXS_Inst  pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst  auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Square annotation atom for the InsertNewAnnot method
            uint nSquare = pxsInst.StrToAtom("Square");
            //Placing it in the center of page
            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY - 100;
            rcOut.right  = nCX + 200;
            rcOut.top    = nCY + 100;
            IPXC_Annotation             annot = page.InsertNewAnnot(nSquare, ref rcOut);
            IPXC_AnnotData_SquareCircle aData = annot.Data as IPXC_AnnotData_SquareCircle;

            aData.Opacity = 0.7;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 1.0f, 1.0f);
            aData.Color = color;
            //Setting dashed border pattern
            var border = new PXC_AnnotBorder();

            border.nStyle       = PXC_AnnotBorderStyle.ABS_Dashed;
            border.nWidth       = 4.0f;
            border.DashArray    = new float[10];
            border.DashArray[0] = border.DashArray[1] = 16.0f; //Width of dashes
            border.nDashCount   = 2;                           //Number of dashes
            aData.set_Border(border);
            annot.Data = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
Esempio n. 10
0
        static public int AddAttachmentAsAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting File attachment annotation atom for the InsertNewAnnot method
            uint nText = pxsInst.StrToAtom("FileAttachment");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 250;
            rcOut.right  = nCX - 150;
            rcOut.top    = nCY + 300;
            IPXC_Annotation annot = page.InsertNewAnnot(nText, ref rcOut);
            IPXC_AnnotData_FileAttachment aData = annot.Data as IPXC_AnnotData_FileAttachment;

            aData.Contents = "FileAttachment Annotation 1.";
            string                  sFilePath = System.Environment.CurrentDirectory + "\\Documents\\Hobbit.txt";
            IPXC_FileSpec           fileSpec  = Parent.m_CurDoc.CreateEmbeddFile(sFilePath);
            IPXC_EmbeddedFileStream EFS       = fileSpec.EmbeddedFile;

            EFS.UpdateFromFile2(sFilePath);
            aData.FileAttachment = fileSpec;
            annot.Data           = aData;

            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations | (int)Form1.eFormUpdateFlags.efuf_Attachments);
        }
Esempio n. 11
0
        static public void AddStandardStampByIndexInCollection(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }
            IPXC_Pages         pages        = Parent.m_CurDoc.Pages;
            IPXC_Page          firstPage    = pages[0];
            PXC_Rect           rcPB         = firstPage.get_Box(PXC_BoxType.PBox_PageBox);
            IPXC_StampsManager stampManager = Parent.m_pxcInst.StampsManager;
            uint nColIndex           = (uint)stampManager.FindCollection("Standard");
            IPXC_StampsCollection sc = stampManager[nColIndex];
            IPXC_StampInfo        si = null;

            for (uint i = 0; i < sc.Count; i++)
            {
                if (sc[i].ID == "Expired")
                {
                    si = sc[i];
                    break;
                }
            }
            //Creating stamp annotation
            IPXS_Inst pSInt   = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            uint      nStamp  = pSInt.StrToAtom("Stamp");
            double    nHeight = 0;
            double    nWidth  = 0;

            si.GetSize(out nWidth, out nHeight);
            PXC_Rect rc;

            rc.left   = 0;
            rc.right  = nWidth;
            rc.top    = rcPB.top;
            rc.bottom = rc.top - nHeight;
            IPXC_Annotation      annot     = firstPage.InsertNewAnnot(nStamp, ref rc, 0);
            IPXC_AnnotData_Stamp stampData = (IPXC_AnnotData_Stamp)annot.Data;

            stampData.SetStampName(si.ID);
            annot.Data = stampData;
            Marshal.ReleaseComObject(firstPage);
            Marshal.ReleaseComObject(pages);
        }
Esempio n. 12
0
        static public void LoadStampFromTheImageFile(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            //Loading image file
            IAFS_Inst afsInst       = (IAFS_Inst)Parent.m_pxcInst.GetExtension("AFS");
            string    sPath         = System.Environment.CurrentDirectory + "\\Images\\run_24.png";
            IAFS_Name name          = afsInst.DefaultFileSys.StringToName(sPath);
            int       openFileFlags = (int)(AFS_OpenFileFlags.AFS_OpenFile_Read | AFS_OpenFileFlags.AFS_OpenFile_ShareRead);
            IAFS_File destFile      = afsInst.DefaultFileSys.OpenFile(name, openFileFlags);
            //Creating new collection
            IPXC_StampsCollection sc = Parent.m_pxcInst.StampsManager.CreateEmptyCollection("My Stamps");

            IPXC_StampInfo si        = sc.AddStamp(destFile, "My Stamp");
            IPXC_Pages     pages     = Parent.m_CurDoc.Pages;
            IPXC_Page      firstPage = pages[0];
            PXC_Rect       rcPB      = firstPage.get_Box(PXC_BoxType.PBox_PageBox);
            //Creating stamp annotation
            IPXS_Inst pSInt   = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            uint      nStamp  = pSInt.StrToAtom("Stamp");
            double    nHeight = 0;
            double    nWidth  = 0;

            si.GetSize(out nWidth, out nHeight);
            //Increasing width and height by 20
            PXC_Rect rc;             //Annotation rectangle

            rc.left   = 0;
            rc.right  = nWidth * 20;
            rc.top    = rcPB.top;
            rc.bottom = rc.top - nHeight * 20;
            IPXC_Annotation      annot     = firstPage.InsertNewAnnot(nStamp, ref rc, 0);
            IPXC_AnnotData_Stamp stampData = (IPXC_AnnotData_Stamp)annot.Data;

            stampData.set_BBox(rc);             //Stamp rectangle boundaries
            stampData.SetStampName(si.ID);
            annot.Data = stampData;
            Marshal.ReleaseComObject(firstPage);
            Marshal.ReleaseComObject(pages);
        }
Esempio n. 13
0
        static public void LoadStampsCollectionFromFile(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            //Loading stamp collection from stamp file
            IAFS_Inst             afsInst       = (IAFS_Inst)Parent.m_pxcInst.GetExtension("AFS");
            string                sPath         = System.Environment.CurrentDirectory + "\\Documents\\MyStamps.pdf";
            IAFS_Name             name          = afsInst.DefaultFileSys.StringToName(sPath);
            int                   openFileFlags = (int)(AFS_OpenFileFlags.AFS_OpenFile_Read | AFS_OpenFileFlags.AFS_OpenFile_ShareRead);
            IAFS_File             destFile      = afsInst.DefaultFileSys.OpenFile(name, openFileFlags);
            IPXC_StampsCollection sc            = Parent.m_pxcInst.StampsManager.LoadCollection(destFile);

            //Placing stamp from the loaded collection
            IPXC_Pages     pages     = Parent.m_CurDoc.Pages;
            IPXC_Page      firstPage = pages[0];
            PXC_Rect       rcPB      = firstPage.get_Box(PXC_BoxType.PBox_PageBox);
            IPXC_StampInfo si        = sc[0];      //getting stamp by index - they are sorted by name
            //Creating stamp annotation
            IPXS_Inst pSInt   = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            uint      nStamp  = pSInt.StrToAtom("Stamp");
            double    nHeight = 0;
            double    nWidth  = 0;

            si.GetSize(out nWidth, out nHeight);
            PXC_Rect rc;            //Annotation rectangle

            rc.left   = 0;
            rc.right  = nWidth;
            rc.top    = rcPB.top;
            rc.bottom = rc.top - nHeight;
            IPXC_Annotation      annot     = firstPage.InsertNewAnnot(nStamp, ref rc, 0);
            IPXC_AnnotData_Stamp stampData = (IPXC_AnnotData_Stamp)annot.Data;

            stampData.set_BBox(rc);             //Stamp rectangle boundaries
            stampData.SetStampName(si.ID);
            annot.Data = stampData;
            Marshal.ReleaseComObject(firstPage);
            Marshal.ReleaseComObject(pages);
        }
Esempio n. 14
0
        static public int AddNewDictionaryToDocumentsRoot(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.OpenDocFromStringPath(Parent);
            }
            IPXS_Inst pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS");
            //Getting structure document
            IPXS_Document structDoc = Parent.m_CurDoc.CosDocument;

            //Locking document for write
            structDoc.LockDocumentExclusive();
            //Creating new indirect variant of the Dictionary type that will hold some elements
            IPXS_PDFVariant varHolder = pxsInst.NewVar_Dict(structDoc, true);

            //Adding our newly created variant to the root dictionary
            structDoc.Root.Dict_Set("TestDataHolder", varHolder);
            //Creating an item that will hold some custom data and will link to the bookmarks root
            IPXS_PDFVariant varBookItem = pxsInst.NewVar_Dict(structDoc, true);

            //Adding that item to the holder dictionary
            varHolder.Dict_Set("BookmarkItem", varBookItem);
            //Setting some custom fields for this item
            varBookItem.Dict_SetBool("IsRoot", true);
            varBookItem.Dict_SetName("CustName", "Root Link");
            varBookItem.Dict_SetInt("CustInt", 123);
            //Setting a link to the bookmark's Root object
            IPXC_Bookmark root = Parent.m_CurDoc.BookmarkRoot;

            //If we have at least one bookmark in the document, then the root won't be null
            if (root != null)
            {
                varBookItem.Dict_Set("BookmarkLink", root.PDFObject);
            }
            //Unlocking the document, since we've finished all of the work with it
            structDoc.UnlockDocumentExclusive();

            return((int)Form1.eFormUpdateFlags.efuf_All);
        }
        static public int AddSquareAndCircleAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Square and Circle annotations atom for the InsertNewAnnot method
            uint nSquare = pxsInst.StrToAtom("Square");
            uint nCircle = pxsInst.StrToAtom("Circle");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 200;
            rcOut.right  = nCX + 200;
            rcOut.top    = nCY + 300;
            IPXC_Annotation             annot = unchecked (page.InsertNewAnnot(nSquare, ref rcOut));
            IPXC_AnnotData_SquareCircle aData = annot.Data as IPXC_AnnotData_SquareCircle;

            aData.Title = "Square annotation 1.";
            annot.Data  = aData;

            rcOut.bottom -= 150;
            rcOut.top    -= 150;
            annot         = unchecked (page.InsertNewAnnot(nSquare, ref rcOut));
            aData         = annot.Data as IPXC_AnnotData_SquareCircle;
            aData.Title   = "Square annotation 2.";
            IColor color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.SColor = color;
            color.SetRGB(0.15f, 0.5f, 0.12f);
            aData.FColor = color;
            annot.Data   = aData;

            rcOut.bottom -= 150;
            rcOut.top    -= 150;
            annot         = unchecked (page.InsertNewAnnot(nCircle, ref rcOut));
            aData         = annot.Data as IPXC_AnnotData_SquareCircle;
            aData.Title   = "Circle annotation 3.";
            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.SColor = color;
            color.SetRGB(0.5f, 0.5f, 0.5f);
            aData.FColor = color;
            //Setting dashed border pattern
            PXC_AnnotBorder border = new PXC_AnnotBorder();

            border.nStyle     = PXC_AnnotBorderStyle.ABS_Dashed;
            border.nWidth     = 4.0f;
            border.DashArray  = new float[] { 10f, 8f, 6f, 4f, 2f, 2f, 4f, 6f, 8f, 10f }; //Width of dashes
            border.nDashCount = 4;                                                        //Number of dashes
            aData.set_Border(border);
            annot.Data = aData;

            rcOut.bottom -= 150;
            rcOut.top    -= 150;
            annot         = unchecked (page.InsertNewAnnot(nCircle, ref rcOut));
            aData         = annot.Data as IPXC_AnnotData_SquareCircle;
            aData.Title   = "Circle annotation 4.";
            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.SColor = color;
            color.SetRGB(0.5f, 0.5f, 0.5f);
            aData.FColor = color;
            //Setting dashed border pattern
            border        = new PXC_AnnotBorder();
            border.nStyle = PXC_AnnotBorderStyle.ABS_Solid;
            border.nWidth = 5.0f;
            aData.set_Border(border);
            annot.Data = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
        static public int AddFreeTextAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Free text annotation atom for the InsertNewAnnot method
            uint nText = pxsInst.StrToAtom("FreeText");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 200;
            rcOut.right  = nCX + 200;
            rcOut.top    = nCY + 300;
            IPXC_Annotation         annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_FreeText aData = annot.Data as IPXC_AnnotData_FreeText;

            aData.Contents = "Free Text Annotation 1.";
            aData.Title    = "Free Text Annotation 1.";
            IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700);

            aData.DefaultFont     = font;
            aData.DefaultFontSize = 40;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.7f, 0.7f, 0.7f);
            aData.DefaultTextColor = color;
            aData.Opacity          = 0.5;
            aData.TextRotation     = 90;
            aData.Subject          = "Typewriter";
            //Setting dashed border pattern
            var border = new PXC_AnnotBorder();

            border.nStyle       = PXC_AnnotBorderStyle.ABS_Beveled;
            border.nWidth       = 4.0f;
            border.DashArray    = new float[15];
            border.DashArray[0] = border.DashArray[1] = 5.0f; //Width of dashes
            border.nDashCount   = 2;                          //Number of dashes
            aData.set_Border(border);
            annot.Data = aData;

            rcOut.bottom         -= 200;
            rcOut.top            -= 200;
            annot                 = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData                 = annot.Data as IPXC_AnnotData_FreeText;
            aData.Contents        = "Free Text Annotation 2.";
            aData.DefaultFontSize = 15.0;
            color                 = auxInst.CreateColor(ColorType.ColorType_RGB);
            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.SColor           = color;
            aData.DefaultTextColor = color;
            //Setting dashed border pattern
            border              = new PXC_AnnotBorder();
            border.nStyle       = PXC_AnnotBorderStyle.ABS_Dashed;
            border.nWidth       = 10.0f;
            border.DashArray    = new float[20];
            border.DashArray[0] = border.DashArray[1] = 5.0f; //Width of dashes
            border.nDashCount   = 4;                          //Number of dashes
            aData.set_Border(border);
            annot.Data = aData;

            rcOut.bottom         -= 200;
            rcOut.top            -= 200;
            annot                 = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData                 = annot.Data as IPXC_AnnotData_FreeText;
            aData.Contents        = "Free Text Annotation 3.";
            color                 = auxInst.CreateColor(ColorType.ColorType_RGB);
            aData.DefaultFontSize = 15.0;
            color.SetRGB(1.0f, 1.0f, 1.0f);
            aData.SColor = color;
            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.DefaultTextColor = color;
            annot.Data             = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
        static public int SortBookmarksByPage(Form1 Parent)
        {
            //delegate double[] GetXYFromDestination(IPXC_Bookmark bookmark, PXC_Destination dest);
            GetXYFromDestination getXYFromDestination = (IPXC_Document doc, PXC_Destination destination) => {
                PXC_DestType Type          = destination.nType;
                PXC_Point    retValue      = new PXC_Point();
                IPXC_Pages   pages         = doc.Pages;
                IPXC_Page    page          = pages[destination.nPageNum];
                PXC_Rect     contentBBox   = page.get_Box(PXC_BoxType.PBox_BBox);
                PXC_Rect     pageBBox      = page.get_Box(PXC_BoxType.PBox_PageBox);
                bool         IsContentType = (Type == PXC_DestType.Dest_FitB) || (Type == PXC_DestType.Dest_FitBH) || (Type == PXC_DestType.Dest_FitBV);
                retValue.x = IsContentType ? contentBBox.left : pageBBox.left;
                retValue.y = IsContentType ? contentBBox.top : pageBBox.top;
                switch (Type)
                {
                case PXC_DestType.Dest_XYZ:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitH:
                {
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitV:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitR:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    if ((destination.nNullFlags & 8) == 0)
                    {
                        retValue.y = destination.dValues[3];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitBH:
                {
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitBV:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    break;
                }

                default:
                    break;
                }
                Marshal.ReleaseComObject(page);
                Marshal.ReleaseComObject(pages);
                return(retValue);
            };
            //delegate void SortByAnything(SortByAnything sort, IPXC_Bookmark root);
            SortByAnything sortByAnything = (sort, root, actionType) => {
                List <Tuple <IPXC_Bookmark, PXC_Destination> > bookmarks = new List <Tuple <IPXC_Bookmark, PXC_Destination> >();
                int             MAX_VALUE   = int.MaxValue;
                PXC_Destination invalidDest = new PXC_Destination();
                invalidDest.nPageNum = (uint)MAX_VALUE;

                while (root.ChildrenCount > 0)
                {
                    Tuple <IPXC_Bookmark, PXC_Destination> currentBookmark = Tuple.Create(root.FirstChild, invalidDest);
                    if (root.FirstChild.Actions != null)
                    {
                        for (int i = (int)root.FirstChild.Actions.Count - 1; i >= 0; i--)
                        {
                            if (root.FirstChild.Actions[(uint)i].Type == actionType)
                            {
                                IPXC_Action_Goto actionGoTo = root.FirstChild.Actions[(uint)i] as IPXC_Action_Goto;
                                PXC_Destination  currDest   = actionGoTo.IsNamedDest
                                                                        ? Parent.m_CurDoc.GetNamedDestination(actionGoTo.DestName)
                                                                        : actionGoTo.get_Dest();
                                currentBookmark = Tuple.Create(root.FirstChild, currDest);
                                break;
                            }
                        }
                    }
                    root.FirstChild.Unlink();

                    if ((bookmarks.Count == 0) || (currentBookmark.Item2.nPageNum > bookmarks[bookmarks.Count - 1].Item2.nPageNum))
                    {
                        bookmarks.Add(currentBookmark);
                        continue;
                    }
                    else if (currentBookmark.Item2.nPageNum < bookmarks[0].Item2.nPageNum)
                    {
                        bookmarks.Insert(0, currentBookmark);
                        continue;
                    }

                    int first = 0;
                    int last  = bookmarks.Count;

                    while (first < last)
                    {
                        int mid = first + (last - first) / 2;
                        if (currentBookmark.Item2.nPageNum == bookmarks[mid].Item2.nPageNum)
                        {
                            if ((MAX_VALUE == currentBookmark.Item2.nPageNum) && (MAX_VALUE == bookmarks[mid].Item2.nPageNum))
                            {
                                if (Form1.NativeMethods.StrCmpLogicalW(currentBookmark.Item1.Title, bookmarks[mid].Item1.Title) == 1)
                                {
                                    first = mid + 1;
                                }
                                else
                                {
                                    last = mid;
                                }
                            }
                            else
                            {
                                PXC_Point currentBookmarkXY   = getXYFromDestination(Parent.m_CurDoc, currentBookmark.Item2);
                                PXC_Point bookmarkXY_FromList = getXYFromDestination(Parent.m_CurDoc, bookmarks[mid].Item2);
                                if (currentBookmarkXY.y < bookmarkXY_FromList.y)
                                {
                                    first = mid + 1;
                                }
                                else if (currentBookmarkXY.y > bookmarkXY_FromList.y)
                                {
                                    last = mid;
                                }
                                else
                                {
                                    if (currentBookmarkXY.x < bookmarkXY_FromList.x)
                                    {
                                        last = mid;
                                    }
                                    else
                                    {
                                        first = mid + 1;
                                    }
                                }
                            }
                        }
                        else if (currentBookmark.Item2.nPageNum < bookmarks[mid].Item2.nPageNum)
                        {
                            last = mid;
                        }
                        else
                        {
                            first = mid + 1;
                        }
                    }
                    bookmarks.Insert(last, currentBookmark);
                }

                foreach (Tuple <IPXC_Bookmark, PXC_Destination> bookmark in bookmarks)
                {
                    root.AddChild(bookmark.Item1, true);
                    if (bookmark.Item1.ChildrenCount > 0)
                    {
                        sort(sort, bookmark.Item1, actionType);
                    }
                }
            };

            if (Parent.m_CurDoc == null)
            {
                return(0);
            }

            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS") as IPXS_Inst;
            uint      nGoTo   = pxsInst.StrToAtom("GoTo");

            sortByAnything(sortByAnything, Parent.m_CurDoc.BookmarkRoot, nGoTo);
            return((int)Form1.eFormUpdateFlags.efuf_Bookmarks);
        }
        static public int AddRedactAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page           page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst           pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst           auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_ContentCreator CC      = Parent.m_CurDoc.CreateContentCreator();
            double nCX = (rcPage.right - rcPage.left) / 2.0;
            double nCY = (rcPage.top - rcPage.bottom) / 4.0 * 3.0;

            IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700);

            CC.SetFontSize(30);
            CC.SetFont(font);
            CC.SetColorRGB(0x00000000);
            for (int i = 0; i < 4; i++)
            {
                CC.ShowTextLine(nCX - 190, nCY - (40 * i), "This is a story of long ago.", -1, (uint)PXC_ShowTextLineFlags.STLF_Default | (uint)PXC_ShowTextLineFlags.STLF_AllowSubstitution);
            }
            page.PlaceContent(CC.Detach(), (uint)PXC_PlaceContentFlags.PlaceContent_Replace);
            IPXC_PageText Text = page.GetText(null, false);

            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 150;
            rcOut.bottom = nCY - 100;
            rcOut.right  = nCX + 150;
            rcOut.top    = nCY + 100;
            //Getting Redact annotation atom for the InsertNewAnnot method
            uint                     nText = pxsInst.StrToAtom("Redact");
            IPXC_Annotation          annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_Redaction aData = annot.Data as IPXC_AnnotData_Redaction;

            aData.Title = "Redact annotation 1.";

            IPXC_QuadsF quadsF = Parent.m_pxcInst.CreateQuads();
            uint        afafaf = quadsF.Count;
            PXC_RectF   rectF  = new PXC_RectF();

            Text.GetTextQuads3(8, 75, quadsF, out rectF);
            aData.Quads = quadsF;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.FColor = color;
            aData.SColor = color;
            annot.Data   = aData;

            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
        static public int AddLinkAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Link annotation atom for the InsertNewAnnot method
            uint nText = pxsInst.StrToAtom("Link");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 250;
            rcOut.right  = nCX + 150;
            rcOut.top    = nCY + 300;
            IPXC_Annotation     annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_Link aData = annot.Data as IPXC_AnnotData_Link;

            aData.Contents     = "Link Annotation 1.";
            aData.HighlighMode = PXC_AnnotHighlightMode.AHM_Outline;
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.8f, 0.8f);
            aData.Color = color;
            //Setting dashed border pattern
            var border = new PXC_AnnotBorder();

            border.nStyle       = PXC_AnnotBorderStyle.ABS_Dashed;
            border.nWidth       = 4.0f;
            border.DashArray    = new float[10];
            border.DashArray[0] = border.DashArray[1] = 16.0f; //Width of dashes
            border.nDashCount   = 2;                           //Number of dashes
            aData.set_Border(border);
            //Setting the annotation's URI action
            IPXC_ActionsList AL = Parent.m_CurDoc.CreateActionsList();

            AL.AddURI("https://www.google.com");
            annot.set_Actions(PXC_TriggerType.Trigger_Up, AL);
            annot.Data = aData;

            rcOut.bottom  -= 200;
            rcOut.top     -= 200;
            annot          = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData          = annot.Data as IPXC_AnnotData_Link;
            aData.Contents = "Link Annotation 2.";
            color          = auxInst.CreateColor(ColorType.ColorType_RGB);
            color.SetRGB(0.5f, 0.4f, 0.48f);
            aData.Color = color;
            //Setting the annotation's Goto action
            PXC_Destination dest = new PXC_Destination();

            dest.nPageNum   = page.Number + 1;
            dest.nType      = PXC_DestType.Dest_XYZ;
            dest.nNullFlags = 15;
            AL = Parent.m_CurDoc.CreateActionsList();
            AL.AddGoto(dest);
            annot.set_Actions(PXC_TriggerType.Trigger_Up, AL);
            annot.Data = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
        static public int AddPolygonAndPolylineAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Polygon and Polyline annotations atom for the InsertNewAnnot method
            string sPolygon  = "Polygon";
            string sPolyline = "PolyLine";
            uint   nText     = pxsInst.StrToAtom(sPolygon);

            for (int p = 0; p < 2; p++)
            {
                double   nCX   = (rcPage.right - rcPage.left) / 2.0;
                double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
                PXC_Rect rcOut = new PXC_Rect();
                rcOut.left   = nCX - 150;
                rcOut.bottom = nCY + 200;
                rcOut.right  = nCX + 150;
                rcOut.top    = nCY + 300;
                if (p > 0)
                {
                    nText        = pxsInst.StrToAtom(sPolyline);
                    rcOut.bottom = nCY - 200;
                    rcOut.top    = nCY - 100;
                }


                IPXC_Annotation     annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
                IPXC_AnnotData_Poly aData = annot.Data as IPXC_AnnotData_Poly;
                aData.Title  = (p == 0) ? sPolygon : sPolyline;
                aData.Title += " annotation 1.";
                IPXC_PolygonSrcF poly = aData.Vertices;
                double           r    = 1.5 * 72.0;
                double           a    = -90.0;
                poly.Clear();
                for (int i = 0; i < 4 + p; i++)
                {
                    PXC_PointF pointF = new PXC_PointF();
                    pointF.x = (float)(rcOut.left + r * Math.Cos(a * Math.PI / 180.0));
                    pointF.y = (float)(rcOut.bottom - r * Math.Sin(a * Math.PI / 180.0));
                    a       += 360.0 / 4;
                    poly.Insert(ref pointF, 1, uint.MaxValue);
                }
                aData.Vertices = poly;
                IColor color = auxInst.CreateColor(ColorType.ColorType_RGB);
                color.SetRGB(0.5f, 0.2f, 0.2f);
                aData.FColor = color;
                color.SetRGB(0.0f, 0.0f, 0.0f);
                aData.SColor = color;

                annot.Data = aData;

                annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
                aData        = annot.Data as IPXC_AnnotData_Poly;
                aData.Title  = (p == 0) ? sPolygon : sPolyline;
                aData.Title += " annotation 2.";
                poly         = aData.Vertices;
                poly.Clear();
                for (int i = 0; i < 6 + p; i++)
                {
                    PXC_PointF pointF = new PXC_PointF();
                    pointF.x = (float)(nCX + r * Math.Cos(a * Math.PI / 180.0));
                    pointF.y = (float)(rcOut.bottom - r * Math.Sin(a * Math.PI / 180.0));
                    a       += 360.0 / 6;
                    poly.Insert(ref pointF, 1, uint.MaxValue);
                }
                aData.Vertices = poly;
                color          = auxInst.CreateColor(ColorType.ColorType_RGB);
                color.SetRGB(0.2f, 0.5f, 0.2f);
                aData.FColor = color;
                color.SetRGB(0.0f, 0.0f, 0.0f);
                aData.SColor = color;
                PXC_AnnotBorder border = new PXC_AnnotBorder();
                border.nStyle = PXC_AnnotBorderStyle.ABS_Solid;
                border.nWidth = 5.0f;
                aData.set_Border(border);
                aData.BlendMode = PXC_BlendMode.BlendMode_Multiply;
                annot.Data      = aData;


                annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
                aData        = annot.Data as IPXC_AnnotData_Poly;
                aData.Title  = (p == 0) ? sPolygon : sPolyline;
                aData.Title += " annotation 3.";
                poly         = aData.Vertices;
                poly.Clear();
                for (int i = 0; i < 8 + p; i++)
                {
                    PXC_PointF pointF = new PXC_PointF();
                    pointF.x = (float)(rcOut.right + r * Math.Cos(a * Math.PI / 180.0));
                    pointF.y = (float)(rcOut.bottom - r * Math.Sin(a * Math.PI / 180.0));
                    a       += 360.0 / 8;
                    poly.Insert(ref pointF, 1, uint.MaxValue);
                }
                aData.Vertices = poly;
                color          = auxInst.CreateColor(ColorType.ColorType_RGB);
                color.SetRGB(0.2f, 0.2f, 0.5f);
                aData.FColor = color;
                color.SetRGB(0.0f, 0.0f, 0.0f);
                aData.SColor      = color;
                border            = new PXC_AnnotBorder();
                border.nStyle     = PXC_AnnotBorderStyle.ABS_Dashed;
                border.nWidth     = 3.0f;
                border.DashArray  = new float[] { 10f, 8f, 6f, 4f, 2f, 2f, 4f, 6f, 8f, 10f }; //Width of dashes
                border.nDashCount = 4;                                                        //Number of dashes
                aData.set_Border(border);
                aData.BlendMode = PXC_BlendMode.BlendMode_Multiply;
                annot.Data      = aData;
            }
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }
        static public int AddLineAnnotation(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IPXC_UndoRedoData urData    = null;
            IPXC_Pages        pages     = Parent.m_CurDoc.Pages;
            IPXC_Page         firstPage = pages[0];
            PXC_Rect          rcPage    = firstPage.get_Box(PXC_BoxType.PBox_PageBox);

            Marshal.ReleaseComObject(firstPage);
            IPXC_Page page    = pages.InsertPage(0, ref rcPage, out urData);
            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS");
            IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX");
            //Getting Line annotation atom for the InsertNewAnnot method
            uint nText = pxsInst.StrToAtom("Line");

            double   nCX   = (rcPage.right - rcPage.left) / 2.0;
            double   nCY   = (rcPage.top - rcPage.bottom) / 2.0;
            PXC_Rect rcOut = new PXC_Rect();

            rcOut.left   = nCX - 200;
            rcOut.bottom = nCY + 200;
            rcOut.right  = nCX + 200;
            rcOut.top    = nCY + 300;
            PXC_Point startPoint = new PXC_Point();

            startPoint.x = rcPage.left + 50;
            startPoint.y = rcPage.top - 50;
            PXC_Point endPiont = new PXC_Point();

            endPiont.x = rcPage.right - 50;
            endPiont.y = startPoint.y;
            IPXC_Annotation     annot = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            IPXC_AnnotData_Line aData = annot.Data as IPXC_AnnotData_Line;

            aData.Title = "Line annotation 1.";
            var color = auxInst.CreateColor(ColorType.ColorType_RGB);

            color.SetRGB(0.0f, 0.0f, 0.0f);
            aData.Color = color;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            PXC_AnnotBorder border = new PXC_AnnotBorder();

            border.nStyle = PXC_AnnotBorderStyle.ABS_Solid;
            border.nWidth = 3.0f;
            aData.set_Border(border);
            annot.Data = aData;

            startPoint.y = startPoint.y - 50;
            endPiont.y   = startPoint.y;
            annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData        = annot.Data as IPXC_AnnotData_Line;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            aData.Title = "Line annotation 2.";
            aData.Color = color;
            aData.SetLineEndings(PXC_AnnotLineEndingStyle.LE_None, PXC_AnnotLineEndingStyle.LE_OpenArrow);
            aData.set_Border(border);
            annot.Data = aData;

            startPoint.y = startPoint.y - 50;
            endPiont.y   = startPoint.y;
            annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData        = annot.Data as IPXC_AnnotData_Line;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            aData.Title  = "Line annotation 3.";
            aData.Color  = color;
            aData.FColor = color;
            aData.SetLineEndings(PXC_AnnotLineEndingStyle.LE_ClosedArrow, PXC_AnnotLineEndingStyle.LE_ClosedArrow);
            aData.set_Border(border);
            annot.Data = aData;

            startPoint.y = startPoint.y - 50;
            endPiont.y   = startPoint.y;
            annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData        = annot.Data as IPXC_AnnotData_Line;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            aData.Title  = "Line annotation 4.";
            aData.Color  = color;
            aData.FColor = color;
            aData.SetLineEndings(PXC_AnnotLineEndingStyle.LE_Circle, PXC_AnnotLineEndingStyle.LE_None);
            aData.set_Border(border);
            annot.Data = aData;

            startPoint.y = startPoint.y - 50;
            endPiont.y   = startPoint.y;
            annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData        = annot.Data as IPXC_AnnotData_Line;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            aData.Title         = "Line annotation 5.";
            aData.ShowCaption   = true;
            aData.CaptionInLine = true;
            PXC_Size size;

            size.cx = 0;
            size.cy = 10;
            aData.set_CaptionOffset(ref size);
            aData.Contents = "Line annotation 5.";
            aData.Color    = color;
            annot.Data     = aData;

            startPoint.y = startPoint.y - 50;
            endPiont.y   = startPoint.y;
            annot        = unchecked (page.InsertNewAnnot(nText, ref rcOut));
            aData        = annot.Data as IPXC_AnnotData_Line;
            aData.SetLinePoints(ref startPoint, ref endPiont);
            aData.Title               = "Line annotation 6.";
            aData.Color               = color;
            aData.FColor              = color;
            aData.LeaderLine          = 15.0;
            aData.LeaderLineExtension = 15.0;
            aData.set_Border(border);
            annot.Data = aData;
            Marshal.ReleaseComObject(page);
            Marshal.ReleaseComObject(pages);

            return((int)Form1.eFormUpdateFlags.efuf_Annotations);
        }