I have an API (which I cannot tweak) that returns data blob of a PDF file to me. I need to transform it into an actual file and open it in a new tab in frontend.
I plan to use window.open(file_link, target='_blank')
to open it, but I was given the actual content instead of a link. How do I write that data into a file and generate the link?
EDIT:
I followed the "solutions" in the suggested post but none works. My PDFstring is a source string apparently and base64 encoding doesn't do anything to it. (Chrome sees it as a url, actually. Pretty funny.)
I also tried using iframe + escape(PDFstring) which got me to open a new window, but two files I uploaded (which have no encryption) either asks me to provide a password or it simply shows a blank page
Whatever happened after that thread was answered made the thread invalid. The solutions don't work anymore.
EDIT2:
When using https://base64.guru/tools/repair
to repair my string, it says Your string is not a Base64 value. It is a source of a PDF file.
I can directly call that API endpoint (through Postman) and it got me a download button and I can download the file, but when I want to use the same endpoint on frontend, it does return SOME data, but that data cannot be read and cannot be transformed into a PDF
EDIT3:
snippet of what that PDF data looks like
%PDF-1.3
%âãÏÓ
1 0 obj
<<
/FormType 1
/Subtype /Form
/Resources
<<
/Font 2 0 R
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/ExtGState
<<
/gRLs0
<<
/ca .15
>>
>>
>>
/Type /XObject
/BBox [0 0 595.28 841.89]
/Filter [/ASCII85Decode /FlateDecode]
/Length 254
/Matrix [1 0 0 1 0 0]
>>
stream
u^^Ü´¿ª.Æ}rP1 ó
ú@äùзeRØÏ¨L a8 QÀ³©¢ícvôE-ñD²UAut,,íh~¬c®OÅ®k$»p_"½$ ~à£YpZ¿óFŤH¡PH¥é)ÂQ@*ÃdáÂ;qNLoâÀæ´#ßbÀw°è÷½åóvQX}ç־9ÂÅp7ùÅ´àì-ËX
dTw ¦bbñ)ÐG$]ÿ°äÖñøÕÐ ~CXvQûHõQf þ~öþ+}¸eׯÞÇÚÁ´¶J´
endstream
endobj
2 0 obj
<<
/F1 3 0 R
>>
endobj
3 0 obj
<<
/Encoding /WinAnsiEncoding
/Subtype /Type1
/Name /F1
/Type /Font
/BaseFont /Helvetica
>>
endobj
4 0 obj
<<
/Filter /FlateDecode
/Length 10
>>
stream
½Pa_bûûz
endstream
endobj
5 0 obj
<<
/Filter /FlateDecode
/Length 46
>>
stream
/÷ÜUc^ Ù-Æ|daR «¯s¹*;HÒo#X»`²ª?Í
endstream
endobj
...
/Encoding /WinAnsiEncoding
/Subtype /Type1
/Name /F1
/Type /Font
/BaseFont /Helvetica
>>
endobj
9 0 obj
<<
/Filter /FlateDecode
/Length 10
>>
stream
².G`XÝ [
endstream
endobj
10 0 obj
<<
/Filter /FlateDecode
/Length 46
>>
endobj xref
0 20
0000000000 65535 f
0000000015 00000 n
0000000567 00000 n
0000000600 00000 n
0000000709 00000 n
0000000793 00000 n
0000000913 00000 n
0000001455 00000 n
0000001488 00000 n
0000001597 00000 n
0000001681 00000 n
0000001802 00000 n
0000002045 00000 n
0000061818 00000 n
0000061680 00000 n
0000061903 00000 n
0000061939 00000 n
0000064655 00000 n
0000064708 00000 n
0000064858 00000 n
trailer
<<
/Info 19 0 R
/ID [<6fb9561b2e6dae8efff33dbd6911a492><28b448a6527da4b73885e10f7a1655c9>]
/Encrypt 18 0 R
/Root 17 0 R
/Size 20
>>
startxref
65027
%%EOF