-1

I'm testing an API that returns either a PDF or CSV file. How do I handle these files when it returns cryptic when printed. Ideally i want to download it to my local directory or atleast verify that its type is a pdf or csv

example results when PDF file is printed:

x£ìTMs┌0╝δWΦHv⌡$Yû╕╡∙ΦL&ôiªεíG╚─⌐1─ÿf≥∩+√)╨S╔`╞╗┌]i%╜░o+/¥Σ╒é    ₧ü░├┐δè=░ù±+∙¡╛3æⁿò9τJú╣1\Z▐-┘╧ÇÇ)RÉTÉä\ÖéöQ)H╦d(GD" àÇ$ä)(ñáÉé╞Ç╞&Æñí1     a@┬Ç'╨├░Ç ┬S(²~X▒/7■à▀#Ålr╣█÷δ╒▓╗¿₧?╕0r╜öτNεg½σÇ·Mt¿g%⌐w╒╒O╘É∙_5⌐M«!≈ú₧ ┘mσñå▄╩╜▐▌z>δδuk*!h═½σ╢»█²¿╛;n╥┬ѲlXeUσ^│¬⌐╔kms½(╜«₧SK/╞φφ·1²▒ε╢=o├ƒ░╒(>▐╠╢=üKL8îµ@xÜ≥î'ë"=ÿûq.ñ_┬R*EZ▐ &╕xOD▄╦»D}xqD\)á╠ä╩ä=j┘a&óÿ╩b
Ü(Q╤Ñ┤╗ªIº∞τ⌡S█╛±åj╫+r;!V▀8╠|G¥7\█H∞╫f1δÅjBµ╗╓&>Äê█sç&4⌠G╝Râπé>¼üt╓6╘┘é3.Ö)ê╦~╖7┬?╔▓#╒â▓ ╖τó{
endstream
endobj
4 0 obj
<</Contents 2 0 R/Type/Page/Resources<</Font<</F1 1 0 R>>>>/Parent 3 0 R/MediaBox[0 0 595 842]>>
endobj
1 0 obj
<</Subtype/Type1/Type/Font/BaseFont/Helvetica/Encoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Kids[4 0 R]/Type/Pages/Count 1>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</ModDate(D:20170308192353Z)/CreationDate(D:20170308192353Z)/Producer(iText« 5.5.8 ⌐2000-2015 iText Group NV \(AGPL-version\))>>
endobj
xref
0 7
0000000000 65535 f
0000000679 00000 n
0000000015 00000 n
0000000767 00000 n
0000000567 00000 n
0000000818 00000 n
0000000863 00000 n
trailer
<</Info 6 0 R/ID [<913d9d39440298342f897dc3e6f0cc43><913d9d39440298342f897dc3e6f0cc43>]/Root 5 0 R/Size 7>>
%iText-5.5.8
startxref
1008
%%EOF
teddybear123
  • 2,314
  • 6
  • 24
  • 38
  • You can't directly printout a pdf file (you can print a CSV file though). See http://stackoverflow.com/questions/25665/python-module-for-converting-pdf-to-text. Flagged as duplicate. – nir0s Mar 08 '17 at 19:41
  • Possible duplicate of [Python module for converting PDF to text](http://stackoverflow.com/questions/25665/python-module-for-converting-pdf-to-text) – nir0s Mar 08 '17 at 19:42

1 Answers1

0

Every file you download has its MIME-type. You need to set correct MIME-type. When it is PDF document then MIME-type=application/pdf. System then opens file with correct app. Check https://en.wikipedia.org/wiki/Media_type

Joe Bobson
  • 1,216
  • 15
  • 19