Here are the key reasons to use the new updated API provided by GroupDocs.Editor for Java since version 20.8:
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
InputStreamsourceStream=newFileInputStream("C:\\sample.docx");try{InputHtmlDocumenthtmlDoc=EditorHandler.toHtml(sourceStream);// Obtain HTML document content
StringhtmlContent=htmlDoc.getContent();// Edit html in WYSIWYG-editor...
// ...
// Save edited html to original document format
OutputHtmlDocumenteditedHtmlDoc=OutputHtmlDocument.fromMarkup(htmlContent,CommonUtilities.sourcePath+CommonUtilities.sourceResourcesFolder);WordsSaveOptionssaveOptions=newWordsSaveOptions();saveOptions.setOutputFormat(WordFormats.Rtf);OutputStreamoutputStream=newFileOutputStream("C:\\output\\edited.docx");EditorHandler.toDocument(editedHtmlDoc,outputStream,saveOptions);outputStream.close();}catch(Exceptionex){ex.getMessage();}// close stream object to release file for other methods.
inputStream.close();
New coding style
StringdocumentPath="C://sample.docx";try{Editoreditor=newEditor(documentPath);// Obtain editable document from original DOCX document
EditableDocumenteditableDocument=editor.edit();StringhtmlContent=editableDocument.getEmbeddedHtml();// Pass htmlContent to WYSIWYG editor and edit there...
// ...
// Save edited EditableDocument object to some WordProcessing format - DOC for example
WordProcessingSaveOptionssaveOptions=newWordProcessingSaveOptions(WordProcessingFormats.Docx);editor.save(editableDocument,"C:\\output\\edited.docx",saveOptions);}catch(Exceptionex){ex.getMessage();}
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.