- Home
- Forum
- Angular - EJ 2
- Insert a .docx or doc file into another docuemnt file
Insert a .docx or doc file into another docuemnt file
Hi,
Is there any provision to insert a document file into another document file. Actually their is a list of document files(templates). I need to insert the selected template file into the currently opened document file.
I tried read the file and insert it using "documentEditor.editor.insertText()" method. But it showing ascii characters.
And I'm return a json string from my api
WordDocument document = WordDocument.Load(stream, GetFormatType(type.ToLower()));
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
How can I render this to my documenteditor done in angular. I think we can do it using "this.container.documentEditor.editor.insertSection();"
Thanks in advance
Bobbin
SIGN IN To post a reply.
3 Replies
RT
Ramya Thirugnanam
Syncfusion Team
July 2, 2019 12:42 PM UTC
Hi Bobbin,
Thanks for contacting Syncfusion support.
We can achieve this by using server-side approach. We are merging the document with already existing document using Syncfusion.Docio library, then open the merged document in document editor.
Export the current opened document in DocumentEditor to server by using SaveAsBlob API. Please check the below documentation link: https://ej2.syncfusion.com/angular/documentation/document-editor/export/?no-cache=1#export-as-blob
Add the below code snippet in controller file. Then open the return json string in documenteditor.open() method.
|
public string MergeDocument()
{
//Opens the source document
Stream stream = new MemoryStream();
IFormFile file = HttpContext.Request.Form.Files[0];
file.CopyTo(stream);
stream.Position = 0;
Syncfusion.DocIO.DLS.WordDocument sourceDocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);
//Opens the existing document which you want to insert with another document by providing path.
WordDocument destinationDocument = new WordDocument(targetFileName);
//Imports the contents of source document at the end of destination document
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
MemoryStream outputStream = new MemoryStream();
//Saves the destination document
destinationDocument.Save(outputStream, FormatType.Docx);
//closes the document instances
sourceDocument.Close();
destinationDocument.Close();
Syncfusion.EJ2.DocumentEditor.WordDocument wdocument = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(outputStream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(wdocument);
wdocument.Dispose();
//open the string in document editor
return json;
} |
Documentation link for your reference: https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documents
Regards,
Ramya T
Hi Bobbin,Thanks for contacting Syncfusion support.We can achieve this by using server-side approach. We are merging the document with already existing document using Syncfusion.Docio library, then open the merged document in document editor.Export the current opened document in DocumentEditor to server by using SaveAsBlob API. Please check the below documentation link: https://ej2.syncfusion.com/angular/documentation/document-editor/export/?no-cache=1#export-as-blobAdd the below code snippet in controller file. Then open the return json string in documenteditor.open() method.
public string MergeDocument(){//Opens the source documentStream stream = new MemoryStream();IFormFile file = HttpContext.Request.Form.Files[0];file.CopyTo(stream);stream.Position = 0;Syncfusion.DocIO.DLS.WordDocument sourceDocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx);//Opens the existing document which you want to insert with another document by providing path.WordDocument destinationDocument = new WordDocument(targetFileName);//Imports the contents of source document at the end of destination documentdestinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);MemoryStream outputStream = new MemoryStream();//Saves the destination documentdestinationDocument.Save(outputStream, FormatType.Docx);//closes the document instancessourceDocument.Close();destinationDocument.Close();Syncfusion.EJ2.DocumentEditor.WordDocument wdocument = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(outputStream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);string json = Newtonsoft.Json.JsonConvert.SerializeObject(wdocument);wdocument.Dispose();//open the string in document editorreturn json;}Documentation link for your reference: https://help.syncfusion.com/file-formats/docio/working-with-word-document#merging-word-documentsRegards,Ramya T
Hi Ramya,
Thanks for your reply....
RT
Ramya Thirugnanam
Syncfusion Team
July 3, 2019 12:01 PM UTC
Hi Bobbin,
Currently, we do not have any API to insert document at current cursor position. From using Syncfusion.Docio library you insert the document at end of previous document.
We have implemented paste method from this method you can insert the block at current cursor position. This paste method will be available in our Volume 2 release on end of June 2019.
Note: From this paste method, you can merge the document blocks at current position not able to insert at separate section.
Regards,
Ramya T
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
BO Bobbin
- Jul 2, 2019 09:55 AM UTC
- Jul 3, 2019 12:01 PM UTC