Пример #1
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 + "\"");
            }
        }
Пример #2
0
        static public int OpenPasswordProtectedDocument(Form1 Parent)
        {
            string    sPath    = System.Environment.CurrentDirectory + "\\Documents\\PasswordProtected.pdf";
            IAFS_Inst fsInst   = (IAFS_Inst)Parent.m_pxcInst.GetExtension("AFS");
            IAFS_Name destPath = fsInst.DefaultFileSys.StringToName(sPath);             //Converting string to name

            Parent.CloseDocument();
            AuthCallback clbk = new AuthCallback();

            Parent.m_CurDoc = Parent.m_pxcInst.OpenDocumentFrom(destPath, clbk);

            return((int)Form1.eFormUpdateFlags.efuf_All);
        }
Пример #3
0
        public void InitPdfControl()
        {
            var pathToPdfOptimizer = Path.Combine(Environment.CurrentDirectory, "PDFOptimizer.pvp");

            MInst = new PXV_Inst();
            MInst.Init();
            MInst.StartLoadingPlugins();
            MInst.AddPluginFromFile(pathToPdfOptimizer);
            MInst.FinishLoadingPlugins();
            MPxcInst = MInst.GetExtension("PXC") as IPXC_Inst;
            if (MPxcInst != null)
            {
                FsInst = (IAFS_Inst)MPxcInst.GetExtension("AFS");
            }
            Debug.WriteLine("InitPdfControl() succesfull");
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        static public int AddAttachment(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.CreateNewDoc(Parent);
            }

            IAFS_Inst afsInst = Parent.m_pxcInst.GetExtension("AFS");

            IPXC_NameTree           attachments        = Parent.m_CurDoc.GetNameTree("EmbeddedFiles");
            IPXS_PDFVariant         var                = null;
            string                  path               = Environment.CurrentDirectory + "\\Documents\\FeatureChartEU.pdf";
            IPXC_FileSpec           fileSpec           = Parent.m_CurDoc.CreateEmbeddFile(path);
            IPXC_EmbeddedFileStream embeddedFileStream = fileSpec.EmbeddedFile;;

            embeddedFileStream.UpdateFromFile2(path);
            var = fileSpec.PDFObject;
            attachments.Add("FeatureChartEU.pdf", var);
            Marshal.ReleaseComObject(attachments);
            return((int)Form1.eFormUpdateFlags.efuf_Attachments | (int)Form1.eFormUpdateFlags.efuf_Annotations);
        }