|
public HttpResponseMessage ImportFileURL([FromBody]FileUrlInfo param)
{
try
{
using (WebClient client = new WebClient())
{
MemoryStream stream = new MemoryStream(client.DownloadData(param.fileUrl));
Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
stream.Dispose();
return new HttpResponseMessage() { Content = new StringContent(json, Encoding.UTF8, "text/plain") };
}
}
catch (Exception ex)
{
return new HttpResponseMessage() { Content = new StringContent("", Encoding.UTF8, "text/plain") };
}
} |
|
//sample code snippet
container.documentEditor. serialize() |
i'm princy. i am a junior angular developer, i have some doubts regarding ejs syncfusion document editor i am getting api response as a value like. http://localhost//resource/default/filename/1686571037_file_sample_100kB.docx this i can't able to display. i found that u also faced this issue like 3yrs ago. did you find the solution?.
Hi Princy,
Currently we are checking and will update the details by June 16, 2023.
Regards,
Kavitha M
Hi kavitha,
Thanks for your response. Can you explain answer for my question?
Princy, Document Editor’s open API will accept only SFDT json string. No other types will be supported. but all the MS Word file formats can be converted to SFDT using the server-side in ASP.NET Core, ASP.NET MVC and Java.
Kindly refer to the below documentation for converting word documents to SFDT.
https://ej2.syncfusion.com/react/documentation/document-editor/how-to/open-document-by-address
Please check the below sample code snippet for importing file from url.
|
public HttpResponseMessage ImportFileURL([FromBody]FileUrlInfo param) { try {
using (WebClient client = new WebClient()) { MemoryStream stream = new MemoryStream(client.DownloadData(param.fileUrl)); Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx); string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); document.Dispose(); stream.Dispose(); return new HttpResponseMessage() { Content = new StringContent(json, Encoding.UTF8, "text/plain") }; } } catch (Exception ex) { return new HttpResponseMessage() { Content = new StringContent("", Encoding.UTF8, "text/plain") }; } } |
Note: pass the file url to download data.
Kindly check the above and let us know if you need any further assistance with this.
Hi Kavitha,
I am using a python (django) backend. Is there a syncfusion library for python? How do I implement syncfusion with python?
Thanks!
Hi Aliasgar,
Document editor does not have native support to open a document using Python, we can use the .NET Core Wrapper as a Python backend.
GitHub link: EJ2-Document-Editor-Web-Services/Python at master · SyncfusionExamples/EJ2-Document-Editor-Web-Services
Regards,
Dhanush S
So, basically my need is to open a default document whenever the document editor is opened. And as per my understanding (if I'm correct), for that I need to pass the sfdt string in api response from backend (in my case django) so that the document editor (which is running in react frontend) can open it.
Now, my doubt is that how can I convert Base64 to sfdt in python or vice versa and which python libraries will I need to install? A code sample for the same would be very much helpful. Also, how does the "Open" button work in the toolbar? How does it convert the document into sfdt in frontend (react) without the need of backend api being called?
I also want to restrict the editing permissions to certain users. How do I do it?
Thanks!
Hi Aliasgar Taksali,
Regarding Converting Base64 to SFDT:
If you have a base64 string representing a Word document, you can provide it to the import method.
This method is part of a .NET library and can be accessed in Python via a .NET wrapper. This wrapper allows Python to efficiently call the method, process the input, and produce an SFDT file as output. The resulting SFDT file can then be opened on the client side. Please review the import.py file provided, which demonstrates the use of a .NET DLL file and the invocation of the import method in Python.
GitHub Link : https://github.com/SyncfusionExamples/EJ2-Document-Editor-Web-Services/blob/master/Python/API%20files%20in%20Python/import.py
Regarding restrict the editing permissions to certain users:
The Document Editor includes a restrict editing function that allows you to limit the editing capabilities of a document. For further information, please consult the documentation below.
Documentation - https://ej2.syncfusion.com/react/documentation/document-editor/restrict-editing
Regards,
Mohammed Affan C