GroupDocs.Editor for Java empowers developers to effortlessly create and edit documents in various formats, including WordProcessing, Spreadsheet, Presentation, Ebook, and Email. This article provides a comprehensive guide on utilizing GroupDocs.Editor to obtain a new document in a specified format, extracting content from a client, processing it, and ultimately saving it to the resultant document.
Getting Started with GroupDocs.Editor
To initiate the document creation process, the GroupDocs.Editor constructor is employed. This constructor enables the creation of documents in different formats. Let’s explore the key components of the code and how it handles various Document Formats.
1. WordProcessing Document:
ByteArrayOutputStreammemoryStream=newByteArrayOutputStream();// Create a new WordProcessing document and save it.
Editoreditor=newEditor(WordProcessingFormats.Docx);{// Edit the WordProcessing document with default options.
EditableDocumentdefaultWordProcessingDoc=editor.edit();// Edit the WordProcessing document with specified options and some defined settings.
WordProcessingEditOptionswordProcessingEditOptions=newWordProcessingEditOptions();wordProcessingEditOptions.setEnablePagination(false);// Disable pagination for the document.
wordProcessingEditOptions.setEnableLanguageInformation(true);// Enable language information for the document.
wordProcessingEditOptions.setFontExtraction(FontExtractionOptions.ExtractAllEmbedded);// Extract all embedded fonts.
EditableDocumenteditableWordProcessingDocument=editor.edit(wordProcessingEditOptions);editor.save(memoryStream);}
2. Spreadsheet Document:
ByteArrayOutputStreammemoryStream=newByteArrayOutputStream();// Create a new Spreadsheet document and save it.
Editoreditor=newEditor(SpreadsheetFormats.Xlsx);{// Edit the Spreadsheet document with default options.
EditableDocumentdefaultEditableSpreadsheetDocument=editor.edit();// Edit the Spreadsheet document with specified options and some defined settings.
SpreadsheetEditOptionsspreadsheetEditOptions=newSpreadsheetEditOptions();spreadsheetEditOptions.setWorksheetIndex(0);spreadsheetEditOptions.setExcludeHiddenWorksheets(true);EditableDocumenteditableSpreadsheetDocument=editor.edit(spreadsheetEditOptions);editor.save(memoryStream);}
3. Presentation Document:
ByteArrayOutputStreammemoryStream=newByteArrayOutputStream();// Create a new Presentation document and save it.
Editoreditor=newEditor(PresentationFormats.Pptx);{// Edit the Presentation document with default options.
EditableDocumentdefaultEditablePresentationDocument=editor.edit();// Edit the Presentation document with specified options and some defined settings.
PresentationEditOptionspresentationEditOptions=newPresentationEditOptions();presentationEditOptions.setShowHiddenSlides(false);presentationEditOptions.setSlideNumber(0);EditableDocumenteditablePresentationDocument=editor.edit(presentationEditOptions);editor.save(memoryStream);}
4. Email Document:
ByteArrayOutputStreammemoryStream=newByteArrayOutputStream();// Create a new Email document and save it.
Editoreditor=newEditor(EmailFormats.Eml);{// Edit the Email document with default options.
EditableDocumentdefaultEditableEmailDocument=editor.edit();// Edit the Email document with specified options and some defined settings.
EmailEditOptionsemailEditOptions=newEmailEditOptions();emailEditOptions.setMailMessageOutput(MailMessageOutput.All);EditableDocumenteditableEmailDocument=editor.edit(emailEditOptions);editor.save(memoryStream);}
Conclusion
This article has provided a step-by-step guide on leveraging GroupDocs.Editor for Java to create new documents in various formats. By utilizing the constructor and specified edit options, developers can seamlessly integrate document creation and editing capabilities into their applications. Whether it’s a WordProcessing, Spreadsheet, Presentation, Ebook, or Email document, GroupDocs.Editor simplifies the process, offering flexibility and efficiency in document manipulation. For more in-depth information, refer to the official GroupDocs.Editor documentation.
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.