'Convert Content response to PDF file

I'm trying to download a response content made by RestSharp to a PDF file. The response looks as follow:

%PDF-1.3 %���� 1 0 obj <</Creator(Rave \(http://www.nevrona.com/rave\))/Producer(Nevrona Designs; modified using iTextSharp� 5.5.13 �2000-2018 iText Group NV \(AGPL-version\))/CreationDate(D:20060301072826)/ModDate(D:20220322132952+00'00')>> endobj 2 0 obj <</Type/Catalog/Outlines 3 0 R/Pages 4 0 R>> endobj 3 0 obj <</Type/Outlines/Count 0>> endobj 4 0 obj <</Type/Pages/Count 2/Kids[5 0 R 6 0 R]>> endobj 5 0 obj <</Type/Page/Parent 4 0 R/Resources<</Font<</F1 7 0 R>>/ProcSet 8 0 R>>/MediaBox[0 0 612.0000 792.0000]/Contents 9 0 R>> endobj 9 0 obj <</Length 311/Filter/FlateDecode>>stream x����j�0����[h������ɡ(��.b�Q��ɥ��k'$�@�J��;}�β�a�(a�}���EIF�,a�.CQ�� �x���QxyZa����.�ővdD��Hs���5�R&N�b�-�'a[�4(U��z�tg@��B5���iL�O��������*��� ��Zm��荅\�k�Xº���p��)�N��6�%�d{�>&\��Ϲ� �����Ryz��Ř����9s_S�G��V�sNrNy��r���>�d��hv}nr���A;�T�q ��V� �o�/,�� endstream endobj 6 0 obj <</Type/Page/Parent 4 0 R/Resources<</Font<</F1 7 0 R>>/ProcSet 8 0 R>>/MediaBox[0 0 612.0000 792.0000]/Contents 10 0 R>> endobj 10 0 obj <</Length 274/Filter/FlateDecode>>streamx����j�0����[X�1��+��Bi�^z�k�,E#v߾YE��"%�̐��f�p��^���e��=��Y�{��G1HΉnj!+|�_���ϗ�v�=���f+mela�'�{*��7;c��T�r�Z�y���E�V�Z³)n�{�R���&��ۙ�ъ�$7� ����?ݠM{�#F;�%!�,Lg���%͹=֗x�7�$#�y�\�b8�����2r3����z����� �4��)ܡ���q�zVMs��m��� endstream endobj 8 0 obj [/PDF/Text] endobj 7 0 obj <</Type/Font/Subtype/Type1/Name/F1/BaseFont/Helvetica/Encoding/WinAnsiEncoding>> endobj xref 0 11 0000000000 65535 f 0000000015 00000 n 0000000249 00000 n 0000000309 00000 n 0000000351 00000 n 0000000408 00000 n 0000000922 00000 n 0000001428 00000 n 0000001401 00000 n 0000000544 00000 n 0000001059 00000 n trailer <</Size 11/Root 2 0 R/Info 1 0 R/ID [<f998795a7e22d29933469bfd5e5f1262><4f9b4da648cce7f494febec2bfee67e7>]>> %iText-5.5.13 startxref 1524 %%EOF

I have tried using the following code but when opening the file output it says error when opening pdf file.

byte[] buffer = m_client.DownloadData(request);
MemoryStream ms = new MemoryStream(buffer);
FileStream file = new FileStream(@"D:\temp\AA" + ".pdf", FileMode.Create, FileAccess.Write);
ms.WriteTo(file);
file.Close();
ms.Close();


Sources

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

Source: Stack Overflow

Solution Source