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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Receiving Word Document as Base64-encoded string, attempting to open as WordDocument

Thread ID:

Created:

Updated:

Platform:

Replies:

131138 Jun 22,2017 06:31 PM UTC Jul 24,2019 06:58 AM UTC ASP.NET MVC 5
loading
Tags: DocIO
Philip Tenn
Asked On June 22, 2017 06:31 PM UTC

Hello,

I have a distributed PDF Web Service that takes in a Word Document as Base 64 encoded string.  I want to convert that to a PDF.

My code:

WordDocument document = new WordDocument(new MemoryStream(Convert.FromBase64String(value)));
logger.Info("Created Word Document");
DocToPDFConverter conv = new DocToPDFConverter();
//Converts the word document to pdf
pdf = conv.ConvertToPDF(document);
stream = new MemoryStream();
pdf.Save(stream);
stream.Position = 0;
pdf.Close();
document.Close();
//Returns the stream data as Base 64 string
string returnData = Convert.ToBase64String(stream.ToArray());

For some reason, I get an error on the construction of the Word Document:

2017-06-22 14:24:53,440 [1] ERROR GeneratePdf_WCFService.Service1 - System.ArgumentOutOfRangeException: Non-negative number required.
Parameter name: value
   at System.IO.MemoryStream.set_Position(Int64 value)
   at Syncfusion.Compression.Zip.ZipArchive.Open(Stream stream, Boolean closeStream)
   at Syncfusion.DocIO.DLS.Convertors.DocxParser.Read(Stream docStream, WordDocument document)
   at Syncfusion.DocIO.DLS.WordDocument.OpenDocx(Stream stream)
   at Syncfusion.DocIO.DLS.WordDocument.OpenInternal(Stream stream, FormatType formatType, String password)
   at GeneratePdf_WCFService.Service1.GeneratePdf(String value, String type, Str

Anyone ever seen this before?  Any ideas or suggestions?

Thanks,

Philip


Vijay Ramachandran [Syncfusion]
Replied On June 23, 2017 11:26 AM UTC

Hi Philip,

Thank you for contacting Syncfusion support.

We are unable to reproduce the reported ArgumentOutOfRangeException issue with the given code snippet. So, kindly provide us input Word document or sample to reproduce the same issue at our end. Thereby we will analyze further and provide you a prompt solution at the earliest.

Let us know if you have any concern.

Regards,
Vijay R
 


Philip Tenn
Replied On June 24, 2017 02:56 PM UTC

I resolved this.  It was bad code on my end.  I was doing an additional UTF8 encoding of the content that corrupted the Docx file prior to sending the Base64 encoded string to the distributed PDF Conversion Service. 

BAD:                    

    byte[] bytes = Encoding.UTF8.GetBytes(webClient.DownloadString(blobInfo.BlobUri));                    

    base64 = Convert.ToBase64String(bytes);

FIXED:                    

    byte[] bytes = webClient.DownloadData(blobInfo.BlobUri);                    

    base64 = Convert.ToBase64String(bytes);



Vijay Ramachandran [Syncfusion]
Replied On June 26, 2017 04:44 AM UTC

Hi Philip,

Thank you for your update.

We are happy to hear that your problem has been resolved. Please let us know if you have any other questions. We will be happy to assist you as always.

Regards,
Vijay R
 


Nusrat Kabir
Replied On July 22, 2019 11:35 AM UTC

How can I display doc file using the same format as I have used to display pdf?
public ActionResult ShowFile(int id)
      {
          var pictureInDb = _context.FileDetails.FirstOrDefault(c => c.FileDetailId == id); 
      
          byte[] array;
          array = pictureInDb.image;
          var strBase64 = Convert.ToBase64String(array);
          var viewModel = new FileBinderWithStuff();
          if (pictureInDb.Extension == ".jpg")
          {
               viewModel = new FileBinderWithStuff
              {
                  Url = string.Format("data:image/jpg;base64,{0}", strBase64),
                  Extension = pictureInDb.Extension
              };
          }
         
          else
          {
              
               viewModel = new FileBinderWithStuff
              {
                  Url = string.Format("data:Application/pdf;base64,{0}", strBase64),
                  Extension = pictureInDb.Extension
              };
 
          }
         
          return PartialView("_ShowFile", viewModel);
          
      }

Poorani Rajendran [Syncfusion]
Replied On July 24, 2019 06:58 AM UTC

Hi Nusrat,

Thank you for contacting Syncfusion support.

Regarding How can I display doc file using the same format as I have used to display pdf?

Could you please confirm us whether you need to display DOC format file in viewer or need to generate DOC format Word document. From the given details, we have not found the complete details of your end requirement. So, could you please share us the more details on your requirement, which will be more helpful to check at our end and will provide you the appropriate solution at the earliest.

If you wish to generate DOC Word document programmatically, we suggest you to refer the below documentation link to know more about generating Word document using Essential DocIO.
https://help.syncfusion.com/file-formats/docio/word-file-formats#word-binary-97-2003-format

Please let me know if you have any other questions.


Regards,
Poorani Rajendran


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

;