示例#1
0
 private void btnBrowseForOpen_Click(object sender, EventArgs e)
 {
     PDFXEdit.IAFS_NamesCollection openFiles = mainFrm.ShowOpenFilesDlg(false, "PDF Documents (*.pdf)|*.pdf|All Files (*.*)|*.*");
     if (openFiles == null)
     {
         return;
     }
     PDFXEdit.IAFS_Name fileName = openFiles[0];
     tSrcToOpen.Text = fileName.FileSys.NameToString(fileName);
     mainFrm.AllowRunOper(IsValid());
 }
示例#2
0
        public virtual bool Run(MainFrm mainFrm, bool bShowOpDlg, bool bAllowOpUI)
        {
            PDFXEdit.IOperation op = null;
            try
            {
                op = mainFrm.pdfCtl.Inst.CreateOp(ID);
            }
            catch
            {
                return(false);
            }

            if (op == null)
            {
                return(false);
            }

            Form ui = UI;

            if (ui != null)
            {
                IFormHelper hlp = (IFormHelper)ui;
                if (hlp != null)
                {
                    hlp.OnSerialize(op);
                }
            }

            uint flags = Flags;

            if ((flags & (uint)DemoFlags.Input_Doc) != 0)
            {
                PDFXEdit.IPXV_Document doc = mainFrm.pdfCtl.Doc;
                if (doc == null)
                {
                    return(false);
                }
                PDFXEdit.ICabNode input = op.Params.Root["Input"];
                if (input.Type == PDFXEdit.CabDataTypeID.dt_Array)
                {
                    input.Add().v = doc;
                }
                else
                {
                    input.v = doc;
                }
            }
            else if (!bShowOpDlg && ((flags & (uint)DemoFlags.Input_Mask) != 0))
            {
                string fileFilter = "";
                if ((flags & (uint)DemoFlags.Input_AllSupp) != 0)
                {
                    fileFilter = "<allSupp>";
                }
                else if ((flags & (uint)DemoFlags.Input_AllSuppImg) != 0)
                {
                    fileFilter = "<allSuppImg>";
                }
                else if ((flags & (uint)DemoFlags.Input_AllSuppRasterImg) != 0)
                {
                    fileFilter = "<allSuppRasterImg>";
                }
                else if ((flags & (uint)DemoFlags.Input_PdfFile) != 0)
                {
                    fileFilter = "PDF Documents (*.pdf)|*.pdf";
                }
                else if ((flags & (uint)DemoFlags.Input_TxtFile) != 0)
                {
                    fileFilter = "Plain Text Documents (*.txt)|*.txt";
                }
                else if ((flags & (uint)DemoFlags.Input_RtfFile) != 0)
                {
                    fileFilter = "RTF Files (*.rtf)|*.rtf";
                }

                PDFXEdit.IAFS_NamesCollection fileNames = mainFrm.ShowOpenFilesDlg((flags & (uint)DemoFlags.Input_MultFiles) != 0, fileFilter);
                if (fileNames == null || (fileNames.Count == 0))
                {
                    return(false);
                }

                PDFXEdit.ICabNode input = op.Params.Root["Input"];
                if (input.Type == PDFXEdit.CabDataTypeID.dt_Array)
                {
                    for (uint i = 0; i < fileNames.Count; i++)
                    {
                        input.Add().v = fileNames[i];
                    }
                }
                else
                {
                    input.v = fileNames[0];
                }
            }

            if (bShowOpDlg)
            {
                try
                {
                    op.ShowSetupUI((uint)mainFrm.Handle);
                }
                catch (Exception ex)
                {
                    int hr = Marshal.GetHRForException(ex);
                    if (hr != HResults.E_NOTIMPL)
                    {
                        return(false);
                    }
                }
            }

            if (!OnBeforeRun(mainFrm, op))
            {
                return(false);
            }


            int opExecFlags = 0;

            if (!bAllowOpUI)
            {
                opExecFlags |= (int)PDFXEdit.OpExecFlags.OpExecFlag_NoUI;
            }

            try
            {
                if ((flags & (int)DemoFlags.SyncDo) != 0)
                {
                    op.Do(opExecFlags);
                }
                else
                {
                    mainFrm.pdfCtl.Inst.AsyncDoAndWaitForFinish(op, (uint)opExecFlags);
                }
            }
            catch (Exception ex)
            {
                int hr = Marshal.GetHRForException(ex);
                mainFrm.ShowErrMsg(hr);

                return(false);
            }

            if ((flags & (int)DemoFlags.Output_Doc) != 0)
            {
                PDFXEdit.ICabNode      output     = op.Params.Root["Output"];
                PDFXEdit.IPXC_Document newCoreDoc = null;
                try
                {
                    if (output.Type == PDFXEdit.CabDataTypeID.dt_Array)
                    {
                        if (output.Count != 0)
                        {
                            newCoreDoc = (PDFXEdit.IPXC_Document)output[0].Unknown;
                        }
                    }
                    else
                    {
                        newCoreDoc = (PDFXEdit.IPXC_Document)output.Unknown;
                    }

                    if (newCoreDoc != null)
                    {
                        mainFrm.pdfCtl.OpenDocFrom(newCoreDoc);
                    }
                }
                catch { }
            }

            return(true);
        }