Here are the key reasons to use the new updated API provided by GroupDocs.Editor for .NET since version 19.9:
Editor class introduced as a single entry point to manage the document editing process to any supported file format (instead of EditorHander class from previous versions).
Product architecture was redesigned from scratch in order to decreased memory usage (from 10% to 400% approx. depending on document type).
Document editing and saving options simplified so it’s easy to instantiate proper options class and control over document editing and saving processes.
How To Migrate?
Here is a brief comparison of how to edit document in HTML form using old and new API.
Old coding style
stringdocumentPath=@"C:\sample.docx";// Obtain document streamStreamsourceStream=File.Open(documentPath,FileMode.Open,FileAccess.Read);using(InputHtmlDocumenthtmlDoc=EditorHandler.ToHtml(sourceStream)){// Obtain HTML document contentstringhtmlContent=htmlDoc.GetContent();// Edit html in WYSIWYG-editor...// ...// Save edited html to original document formatusing(OutputHtmlDocumenteditedHtmlDoc=OutputHtmlDocument.FromMarkup(htmlContent,Path.Combine(Common.sourcePath,Common.resultResourcesFolder))){using(System.IO.FileStreamoutputStream=System.IO.File.Create(@"C:\output\edited.docx")){WordProcessingSaveOptionssaveOptions=newWordProcessingSaveOptions();EditorHandler.ToDocument(editedHtmlDoc,outputStream,saveOptions);}}}// close stream object to release file for other methods.sourceStream.Close();
New coding style
stringdocumentPath=@"C:\sample.docx";using(Editoreditor=newEditor(documentPath)){// Obtain editable document from original DOCX documentEditableDocumenteditableDocument=editor.Edit();stringhtmlContent=editableDocument.GetEmbeddedHtml();// Pass htmlContent to WYSIWYG editor and edit there...// ...// Save edited EditableDocument object to some WordProcessing format - DOC for exampleWordProcessingSaveOptionssaveOptions=newWordProcessingSaveOptions(Formats.WordProcessingFormats.Docx);editor.Save(editableDocument,@"C:\output\edited.docx",saveOptions);}
For more code examples and specific use cases please refer to our Developer Guide documentation or GitHub samples and showcases.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.