コード例 #1
0
 public CloseEditor(EditableDocument Document, DockablePanel Editor, bool AppClosing)
 {
     this.Document   = Document;
     this.Editor     = Editor;
     this.AppClosing = AppClosing;
     Succeeded       = false;
 }
        public HttpResponseMessage SaveFile(EditDocumentRequest postedData)
        {
            try
            {
                string htmlContent  = postedData.getContent(); // Initialize with HTML markup of the edited document
                string guid         = postedData.GetGuid();
                string password     = postedData.getPassword();
                string saveFilePath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), guid);
                string tempFilename = Path.GetFileNameWithoutExtension(saveFilePath) + "_tmp";
                string tempPath     = Path.Combine(Path.GetDirectoryName(saveFilePath), tempFilename + Path.GetExtension(saveFilePath));

                ILoadOptions loadOptions = GetLoadOptions(guid);
                if (loadOptions != null)
                {
                    loadOptions.Password = password;
                }

                // Instantiate Editor object by loading the input file
                using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(guid, delegate { return(loadOptions); }))
                {
                    EditableDocument htmlContentDoc = EditableDocument.FromMarkup(htmlContent, null);
                    dynamic          saveOptions    = GetSaveOptions(guid);

                    if (!(saveOptions is TextSaveOptions))
                    {
                        saveOptions.Password = password;
                    }

                    if (saveOptions is WordProcessingSaveOptions)
                    {
                        saveOptions.EnablePagination = true;
                    }

                    using (FileStream outputStream = File.Create(tempPath))
                    {
                        editor.Save(htmlContentDoc, outputStream, saveOptions);
                    }
                }

                if (File.Exists(saveFilePath))
                {
                    File.Delete(saveFilePath);
                }

                File.Move(tempPath, saveFilePath);

                LoadDocumentEntity loadDocumentEntity = LoadDocument(saveFilePath, password);

                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity));
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, postedData.getPassword())));
            }
        }
コード例 #3
0
        protected void butDownloadHTML_Click(object sender, EventArgs e)
        {
            if (fileupload.HasFile)
            {
                try
                {
                    string myDate                     = DateTime.Now.ToString("MM-dd-yyyy--H-mm-ss--");
                    string filename                   = Path.GetFileName(fileupload.FileName);
                    string fullpath                   = Server.MapPath("/Uploaded/") + myDate + filename;
                    string fullpathExportDocX         = fullpath.Replace(".docx", "-GroupDocsExport.docx");
                    string fullpathExportEmbeddedHTML = fullpath.Replace(".docx", "-GroupDocsExportEmbedded.html");
                    string fullpathExportHTML         = fullpath.Replace(".docx", "-GroupDocsExport.html");
                    string fullpathExportPDF          = fullpath.Replace(".docx", "-GroupDocsExport.pdf");
                    fullpathExportDocX         = fullpathExportDocX.Replace("Uploaded", "Exported");
                    fullpathExportHTML         = fullpathExportHTML.Replace("Uploaded", "Exported");
                    fullpathExportPDF          = fullpathExportPDF.Replace("Uploaded", "Exported");
                    fullpathExportEmbeddedHTML = fullpathExportEmbeddedHTML.Replace("Uploaded", "Exported");
                    fileupload.SaveAs(fullpath);
                    using (Editor editor = new Editor(fullpath))
                    {
                        WordProcessingEditOptions editOptions = new WordProcessingEditOptions();
                        editOptions.EnablePagination = false;
                        EditableDocument readyToSave = editor.Edit(editOptions);

                        if (!string.IsNullOrEmpty(fullpathExportDocX))
                        {
                            editor.Save(readyToSave, fullpathExportDocX, new WordProcessingSaveOptions(WordProcessingFormats.Docx));
                        }
                        if (!string.IsNullOrEmpty(fullpathExportPDF))
                        {
                            editor.Save(readyToSave, fullpathExportPDF, new PdfSaveOptions());
                        }
                        if (!string.IsNullOrEmpty(fullpathExportHTML))
                        {
                            readyToSave.Save(fullpathExportHTML);
                        }
                        if (!string.IsNullOrEmpty(fullpathExportEmbeddedHTML))
                        {
                            var html = readyToSave.GetEmbeddedHtml();
                            File.WriteAllText(fullpathExportEmbeddedHTML, html);
                        }

                        readyToSave.Dispose();
                        editor.Dispose();
                    }
                    lblStatus.Text = "Upload status: File uploaded and converted!";
                }
                catch (Exception ex)
                {
                    lblStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
        public HttpResponseMessage CreateFile(EditDocumentRequest postedData)
        {
            try
            {
                string htmlContent  = postedData.getContent();
                string guid         = postedData.GetGuid();
                string saveFilePath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), guid);
                string tempFilename = Path.GetFileNameWithoutExtension(saveFilePath) + "_tmp";
                string tempPath     = Path.Combine(Path.GetDirectoryName(saveFilePath), tempFilename + Path.GetExtension(saveFilePath));

                File.Create(saveFilePath).Dispose();

                using (EditableDocument newFile = EditableDocument.FromMarkup(htmlContent, null))
                {
                    using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(saveFilePath))
                    {
                        dynamic saveOptions = this.GetSaveOptions(saveFilePath);
                        if (saveOptions is WordProcessingSaveOptions)
                        {
                            // TODO: saveOptions.EnablePagination = true here leads to exception
                        }

                        using (FileStream outputStream = File.Create(tempPath))
                        {
                            editor.Save(newFile, outputStream, saveOptions);
                        }
                    }
                }

                if (File.Exists(saveFilePath))
                {
                    File.Delete(saveFilePath);
                }

                File.Move(tempPath, saveFilePath);

                LoadDocumentEntity loadDocumentEntity = LoadDocument(saveFilePath, "");

                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity));
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, postedData.getPassword())));
            }
        }
        private LoadDocumentEntity LoadDocument(string guid, string password)
        {
            LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();

            loadDocumentEntity.SetGuid(guid);
            ILoadOptions loadOptions = GetLoadOptions(guid);

            if (loadOptions != null)
            {
                loadOptions.Password = password;
            }

            // Instantiate Editor object by loading the input file
            using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(guid, delegate { return(loadOptions); }))
            {
                IDocumentInfo documentInfo = editor.GetDocumentInfo(password);

                dynamic editOptions = GetEditOptions(guid);
                if (editOptions is WordProcessingEditOptions)
                {
                    editOptions.EnablePagination = true;

                    // Open input document for edit — obtain an intermediate document, that can be edited
                    EditableDocument      beforeEdit = editor.Edit(editOptions);
                    string                allEmbeddedInsideString = beforeEdit.GetEmbeddedHtml();
                    PageDescriptionEntity page = new PageDescriptionEntity();
                    page.SetData(allEmbeddedInsideString);
                    loadDocumentEntity.SetPages(page);
                    beforeEdit.Dispose();
                }
                else if (editOptions is SpreadsheetEditOptions)
                {
                    for (var i = 0; i < documentInfo.PageCount; i++)
                    {
                        // Let's create an intermediate EditableDocument from the i tab
                        SpreadsheetEditOptions sheetEditOptions = new SpreadsheetEditOptions();
                        sheetEditOptions.WorksheetIndex = i; // index is 0-based
                        EditableDocument tabBeforeEdit = editor.Edit(sheetEditOptions);

                        // Get document as a single base64-encoded string, where all resources (images, fonts, etc)
                        // are embedded inside this string along with main textual content
                        string allEmbeddedInsideString = tabBeforeEdit.GetEmbeddedHtml();
                        PageDescriptionEntity page     = new PageDescriptionEntity();
                        page.SetData(allEmbeddedInsideString);
                        page.number = i + 1;
                        loadDocumentEntity.SetPages(page);
                        tabBeforeEdit.Dispose();
                    }
                }
                else if (editOptions is PresentationEditOptions)
                {
                    for (var i = 0; i < documentInfo.PageCount; i++)
                    {
                        // Create editing options
                        PresentationEditOptions presentationEditOptions = new PresentationEditOptions();
                        // Specify slide index from original document.
                        editOptions.SlideNumber = i; // Because index is 0-based, it is 1st slide
                        EditableDocument slideBeforeEdit = editor.Edit(presentationEditOptions);

                        // Get document as a single base64-encoded string, where all resources (images, fonts, etc)
                        // are embedded inside this string along with main textual content
                        string allEmbeddedInsideString = slideBeforeEdit.GetEmbeddedHtml();
                        PageDescriptionEntity page     = new PageDescriptionEntity();
                        page.SetData(allEmbeddedInsideString);
                        page.number = i + 1;
                        loadDocumentEntity.SetPages(page);
                        slideBeforeEdit.Dispose();
                    }
                }
            }

            return(loadDocumentEntity);
        }
コード例 #6
0
        public void Execute(Model Model, Main View)
        {
            try
            {
                var         extension   = System.IO.Path.GetExtension(FileName);
                OpenCommand realCommand = null;

                if (extension == ".txt")
                {
                    realCommand = new OpenCommand <TextDocument>(FileName, OpenStyle);
                }

                /* else if (extension == ".ms")
                 *  realCommand = new OpenCommand<ManuscriptDocument>(FileName, OpenStyle);
                 * else if (extension == ".$prose")
                 *  realCommand = new OpenCommand<SceneDocument>(FileName, OpenStyle);
                 * else if (extension == ".$settings" && FileName.Contains('&'))
                 *  realCommand = new OpenCommand<SceneSettingsDocument>(FileName, OpenStyle);
                 * else if (extension == ".$settings")
                 *  realCommand = new OpenCommand<ManuscriptSettingsDocument>(FileName, OpenStyle);
                 */
                else if (extension == ".$notes")
                {
                    realCommand = new OpenCommand <NotesDocument>(FileName, OpenStyle);
                }

                /*else if (extension == ".$find")
                 *  realCommand = new OpenCommand<FindDocument>(FileName, OpenStyle);*/
                else if (System.IO.Directory.Exists(FileName))
                {
                    realCommand = new OpenCommand <FolderDocument>(FileName, OpenStyle);
                }
                else
                {
                    throw new InvalidOperationException("Unknown file type");
                }

                realCommand.Execute(Model, View);
                Succeeded = realCommand.Succeeded;
                Document  = realCommand.Document;
                Panel     = realCommand.Panel;

                if (Succeeded == false && OpenStyle == OpenCommand.OpenStyles.CreateView)
                {
                    System.Windows.Forms.MessageBox.Show(String.Format("Opening {0} failed or was aborted to preserve your data. Error message: {1}",
                                                                       FileName, realCommand.ErrorMessage));
                }

                if (Succeeded == true && OpenStyle == OpenCommand.OpenStyles.CreateView)
                {
                    Settings.GlobalSettings.RecentDocuments.Remove(FileName);
                    Settings.GlobalSettings.RecentDocuments.Add(FileName);
                    if (Settings.GlobalSettings.RecentDocuments.Count > 10)
                    {
                        Settings.GlobalSettings.RecentDocuments.RemoveAt(0);
                    }

                    View.UpdateRecentDocuments();
                }
            }
            catch (Exception)
            {
                Succeeded = false;
                Panel     = null;
            }
        }
コード例 #7
0
 public SaveDocument(EditableDocument Document)
 {
     this.Document = Document;
     Succeeded     = false;
 }
コード例 #8
0
 public DuplicateView(EditableDocument Document)
 {
     this.Document = Document;
     Succeeded     = false;
 }