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.
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 Jun 26,2017 04:44 AM UTC ASP.NET MVC 3
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
 


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.

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

;