2

I am getting the response below from an API. I want to download the PDF using .net core. I have detailed below two ways that I have tried to download it but still not getting result. I want to download this response after its conversion (in text) in pdf formats.

Response returning from the API is like :

%PDF-1.5
%����
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-GB) /StructTreeRoot 8 0 R/MarkInfo<</Marked true>>>>
endobj
2 0 obj
<</Type/Pages/Count 1/Kids[ 3 0 R] >>
endobj
3 0 obj
<</Type/Page/Parent 2 0 R/Resources<</Font<</F1 5 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/MediaBox[ 0 0 595.32 841.92] /Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S/StructParents 0>>
endobj
4 0 obj
<</Filter/FlateDecode/Length 185>>
stream
x�u��
�@E����[�f�Y������@��!hH���Ot!��00�=g��2�)�(�QT%
+�d���`�\�X+�q��v���Z�I����{���Y�M �ļ�d#fN�ш)U�q��+����n�c�n����&U"2Z�cAnM�l=M��
��R�vy�Vd6&RA�����E
endstream
endobj
5 0 obj
<</Type/Font/Subtype/TrueType/Name/F1/BaseFont/ABCDEE+Calibri/Encoding/WinAnsiEncoding/FontDescriptor 6 0 R/FirstChar 32/LastChar 116/Widths 16 0 R>>
endobj
6 0 obj
<</Type/FontDescriptor/FontName/ABCDEE+Calibri/Flags 32/ItalicAngle 0/Ascent 750/Descent -250/CapHeight 750/AvgWidth 521/MaxWidth 1743/FontWeight 400/XHeight 250/StemV 52/FontBBox[ -503 -250 1240 750] /FontFile2 17 0 R>>
endobj
7 0 obj
endobj
14 0 obj
<</Type/ObjStm/N 7/First 44/Filter/FlateDecode/Length 296>>
stream
x��R���0�����4j�.����.�H+�A<�:��Db
��;c+փ�y��^f���B(^��"���`�Q��hja��1��@� �qs=&�թ��T�b�
endstream
endobj
16 0 obj
[ 226 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 507 507 507 507 0 0 0 0 0 0 0 0 0 0 0 0 0 0 544 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 459 0 0 0 0 0 0 0 0 0 0 0 0 0 479 0 0 0 498 305 0 0 230 0 0 0 799 525 0 0 0 0 0 335]
endobj
17 0 obj
<</Filter/FlateDecode/Length 81821/Length1 175900>>
stream
x��[ x�չ>��g�,��$�m�̄�B�I [��� $ HH�T 술(
�}C�b�b�e2�WT\�B���[[��K�RA�}���A�Z���i����I�y���?�;�|���3�\�бI���5=?�̔��3�������˜�G����U��+�߽�q�n�1�ί�����T�lY��g5�&6.�

I have tried 1:

[HttpGet]
public ActionResult BenefitStatements(string docId)
{
    var BenefitStatementDtoJson = JsonConvert.SerializeObject(docId, Formatting.Indented);
    buildApiUrlForDocument("getBenefitStatement/", docId);

    var response = _api.GetResponse(apiUrl, authToken);                              
    return File(response, "application/pdf", docId+".pdf");
}

but still failed. I also tried:

string strURL = Response_from_api;
WebClient req = new WebClient();
HttpResponse response = HttpContext.Response;
response.Clear();

response.Headers.Clear();

response.Headers.Add("Content-Disposition", "attachment;filename=mypdf.pdf");
byte[] data = req.DownloadData(Response_from_api);
response.Body.WriteAsync(data);
theduck
  • 2,589
  • 13
  • 17
  • 23
v10518
  • 21
  • 2

0 Answers0