We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Insert a .docx or doc file into another docuemnt file

Thread ID:

Created:

Updated:

Platform:

Replies:

145647 Jul 2,2019 09:55 AM UTC Jul 3,2019 12:01 PM UTC Angular - EJ 2 3
loading
Tags: DocumentEditor
Bobbin
Asked On July 2, 2019 09:55 AM UTC

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

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

Ramya Thirugnanam [Syncfusion]
Replied On 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;  
        }  
  
 
 
Regards, 
Ramya T 


Bobbin
Replied On July 2, 2019 01:49 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;  
        }  
  
 
 
Regards, 
Ramya T 


Hi Ramya,

Thanks for your reply....

Actually I need to append the document at the cursor point. That means if the cursor is pointed between the text of first document then second document should display at that point. Is it possible?

Ramya Thirugnanam [Syncfusion]
Replied On 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  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon