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())));
            }
        }
        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())));
            }
        }