Get error: "Argument is not image byte array" when copy and paste some images from internet

Hello everyone, I'm copying some images from the internet and pasting them into the editor.
Some images generate the error "Argument is not image byte array" when trying to convert content in the backend to RTF format.

Steps to simulate:
1 - Access https://telemedicinamorsch.com.br/blog/interpretacao-da-mamografia and copy any image from page.
2 - P
aste the image into the editor
img1.jpg
3 - Send blob to backend using:

   documentEditor.saveAsBlob("Docx")

4 - Try to convert wordDocument to RTF:  
   wordDocument.Save(memoryStream, WFormatType.Rtf);

img3.jpg


4 Replies

SM Suriya Murugan Syncfusion Team December 22, 2021 03:50 AM UTC

Hi Tiago , 


Syncfusion Greetings! 


In front end, use serialize API to send the document as Sfdt in backend. Then save the sfdt content as RTF format using save API. 

Please check below documentation for reference: 


In this documentation use format as Rtf instead of Docx and let us know if you still facing issue. 

Stream document = WordDocument.Save(data.content, FormatType.Rtf); 
    FileStream file = new FileStream("sample.rtf", FileMode.OpenOrCreate, FileAccess.ReadWrite); 
    document.CopyTo(file); 
    file.Close(); 
    document.Close(); 

 
 
Regards, 
Suriya M. 



TL Tiago Luz December 27, 2021 09:19 PM UTC

Hi Suriya, thank you for answering.
I tried to do the way you indicated but I wasn't successful, an exception occurred.


I created an example for you with 3 sfds, the first with the image copied from the website where the problem is happening and the second is just text and the third an image copied from the Syncfusion website. Only the first sfdt that throws an exception.


Attachment: Sample_af541c62.zip


SM Suriya Murugan Syncfusion Team December 28, 2021 12:23 PM UTC

Hi Tiago, 
  
Thanks for sharing the details. 
  
We can reproduce the issue. Currently, we are validating and get back to you by December 30,2021. 
  
Regards, 
Suriya M. 



SM Suriya Murugan Syncfusion Team December 31, 2021 03:33 AM UTC

Hi Tiago, 

On further validating, we suspect you were using lower version of Document editor. Please upgrade to latest version 19.4.40 and try the reported issue. (copy/paste image and export as Sfdt using Save API. 

Code snippet to save in server side: 

public string ExportSFDT([FromBody] SaveParameter data)
{
string name = data.FileName;
string format = RetrieveFileType(name);
if (string.IsNullOrEmpty(name))
{
name = "Document1.doc";
}
Stream document = WordDocument.Save(data.Content, FormatType.Docx); 
 
string path = _hostingEnvironment.ContentRootPath + "\\App_Data\\Server-sfdt-exporting.docx";

FileStream file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
WDocument dociodocument = new WDocument(document, WFormatType.Docx); 
 
dociodocument.Save(file, WFormatType.Docx);
file.Position = 0;
file.Close();
document.Close();
return "";
//return SaveDocument(document, format, name);
 

But in latest version, we are not facing any exception. But the image is not preserved in the saved RTF file. Based on your confirmation, we will start working on this issue. 
Please let us know if you still facing issue. 

Regards, 
Suriya M. 


Loader.
Up arrow icon