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

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);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source