Convert pdf file received in string variable to byte array in C#

安稳与你 提交于 2019-12-31 04:21:11

问题


I am trying to develop an application in C# which takes data from Service1(3rd party), processes it and then sends data to Service2(again 3rd party).

The data I am trying to receive, process and send is a pdf file

From Service1, I am receiving pdf file in a string variable.

e.g.

response.Content = "%PDF-1.4 \n1 0 obj\n<<\n/Pages 2 0 R\n/Type /Catalog\n>>\nendobj\n2 0 obj\n<<\n/Type /Pages\n/Kids [ 3 0 R 17 0 R ]\n/Count 2\n>>\nendobj\n3 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/Resources <<\n/XObject << /Im0 8 0 R >>\n/ProcSet 6 0 R
>>\n/MediaBox [0 0 ..."

Now, Service2 requires PDF data to be in byte[] form

How do I convert response.Content i.e. string to byte[]?

FYI -

I have tried below method, but it didn't work. I am able to open file but it shows all junk values.

byte[] bitmapData = Encoding.UTF8.GetBytes(response.Content);

UPDATE : SOLVED

I just found that it was not Service1 which was sending data in string format, it's just I was using IRestResponse.Content, a string variable from RestSharp instead of using IRestResponse.RawBytes, a byte[] variable.


回答1:


I just found that it was not Service1 which was sending data in string format, it's just I was using IRestResponse.Content, a string variable from RestSharp instead of using IRestResponse.RawBytes, a byte[] variable.



来源:https://stackoverflow.com/questions/35242758/convert-pdf-file-received-in-string-variable-to-byte-array-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!