title: FileStream response shows � instead latin characters
body: <p>kindly read the whole question,<br>I have a application in C# ASP.NET MVC. Which does a Ajax call on a function which returns a PDF file using <code>FileStream</code> with response <strong>STREAM A</strong>. And due to that it do not renders the file properly. The file is just empty page with no text in it when opened. <br> <code>FilestreamResult</code> in ASP.NET MVC returns a response <strong>STREAM A</strong> while returning a PDF file</p>
  
  <p><strong>STREAM A</strong></p>
  
  <pre><code>%PDF-1.3
  %����
  7 0 obj
  &lt;&lt;
  /Type /ExtGState
  /ca 1
  &gt;&gt;
  endobj
  5 0 obj
  &lt;&lt;
  /Type /Page
  /Parent 1 0 R
  /MediaBox [0 0 595.28 841.89]
  /Contents 3 0 R
  /Resources 4 0 R
  &gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;
  /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
  /Font &lt;&lt;
  /F1 6 0 R
  &gt;&gt;
  /ExtGState &lt;&lt;
  /Gs1 7 0 R
  &gt;&gt;
  &gt;&gt;
  endobj
  8 0 obj
  &lt;&lt;
  /Producer (��pdfmake)
  /Creator (��pdfmake)
  /CreationDate (D:20140526100505Z)
  &gt;&gt;
  endobj
  10 0 obj
  &lt;&lt;
  /Type /FontDescriptor
  /FontName /AAAAAA+Roboto-Regular
  /FontFile2 9 0 R
  /FontBBox [-479 -271 1170 1058]
  /Flags 32
  /StemV 0
  /ItalicAngle 0
  /Ascent 1048
  /Descent -271
  /CapHeight 1048
  /XHeight 0
  &gt;&gt;
  endobj
  6 0 obj
  &lt;&lt;
  /Type /Font
  /BaseFont /AAAAAA+Roboto-Regular
  /Subtype /TrueType
  /FontDescriptor 10 0 R
  /FirstChar 33
  /LastChar 53
  /Widths [586 568 252 523 249 550 568 874 568 252 529 641 659 583 343 346 568 757 345 878 513]
  /Encoding /MacRomanEncoding
  /ToUnicode 11 0 R
  &gt;&gt;
  endobj
  2 0 obj
  &lt;&lt;
  /Type /Catalog
  /Pages 1 0 R
  &gt;&gt;
  endobj
  1 0 obj
  &lt;&lt;
  /Type /Pages
  /Count 1
  /Kids [5 0 R]
  &gt;&gt;
  endobj
  3 0 obj
  &lt;&lt;
  /Length 218
  /Filter /FlateDecode
  &gt;&gt;
  stream
  x���=N�0�~N1����I�bl
  �H6A����שhH,n����Fطs�]�����'
  ����4��O&lt;��
  x^�/Ϋ��J}ӟO��s�ũ�
  ����C(��땞*���щ"��Kٙ���XD��sŶd�f�a�Ŋ&amp;��b8H9Ⴙ��@|Ѵ+,�Ȥ��}dxu%���Ѷ�ME7S����AXUm�j����xWϿ
  endstream
  endobj
  9 0 obj
  &lt;&lt;
  /Length 3042
  /Filter /FlateDecode
  /Length1 4920
  &gt;&gt;
  stream
  x��X
  pSU�?����i�&amp;M�R�4��H۴T��� (P*�|I��MhmS�`��f][l�������CR�.*���#�u����CѝYg����s�{)Iq�d������9�w�9�� ���ohq��6��&lt;r��6\I��)^�=��ipd�OoH��,����y_a�a�/ ^���r$�rģ��hqt��
  � ь���i��Jn�2ĕ��W������m��sg��W8�� �Ij����g
  �cc�ka�Jwf�p������E�mQ;w�8��@���d�����ǵ~2�_@,z��Rl���9�p.�,�_��e�=̬8    �*��vS�FQ�B�b��!�1��ڛvlR��fͲ��\Q�5CTᅝT�y���w���;��A�H���s�u��#ۖ����)��#N����,�EC4� f���3z��/�D~�~~�M���v���/%�!�_��en���,xX����"�����SZ�&gt;y���l�}�uӐ�W�7�\T8�t��ၴDR;����&gt;j8M��2��A`��1NQfVffq�Je�"dLI5��SDkFfI�=5�^8���?2��y����woX�ؙ.�8��HO����^^��ݷu�y\\�y}y�=i9{���d��v�`&lt;7"�����#���D'GXK���Hp��d�_k&lt;�=�E�c�
  �Lֲq�0w��VȌ�i�����^,Ӵfeʙ�|��*)��s�5��$��H���&gt;�m��8A��o��B�m::�=�
  �dV�_ٷ�ئ:�c����7����6�i]���wqu$���5�]2[9�1�j�u==�.�3W�[3��K�u���;�;��Y�bϭ�;�y����\�h�2_�E��/�H�c|� �D��5$F��`RXX����lC��~�鉮O$Q|��y��pۋ�[[\��?�y�:_:�^V�t�o����.��ٝ�7�C��]����b�&lt;����������52;��_d'�
  ������8`��!�b�d��!�H�˅��K�Q��   :���p�&gt;�DM��i��w�!?^
  _��]�w������ǯ,�]�Xr�y6/7{�$����6���!�H=�k�
  rME���\%F{�@&lt;�XY����G�i�����@�E�T��(?�����E�|�F�J�ZbE��,XC����5b8����|�۷˹�dY��/6��Q��CF��}ο�=��/��]�m�R��CS|l��0�=�#\;4X!�e.҄DV��0.@8�l���IJ��$�����:͂��3d!]A�{��p�bxiz���/��.�ߟz����]]8
  �/�ї8�e���d&gt;��x�'��&amp;�   h�O�v��z�,������Ar��Nօ_
  u���/~(��υ/��&gt;�7v����D#�)��C����]�f�F�V ��jl�g�)]M63�y�����n��&amp;�;]eC�촜�_U��1�����Ɇ'�Z��c�*-�F����CMA�������C�X#��2�d�����"�F��@`a���$�d��~B�B����Jˠ=��MiA�!��5����"��
  ��@�oT����L7
  ���F�ZĜ�1�$)S�z&amp;�ꨕ���
  ���C�ۍV\��g�[����̙yE��)�5ٝ�G�
  ��7zC��s���ɦ'��'{����P��z
  +���*��ܺ��i��6@�}�̯�%�.���m1�ō�eo����V~���(�����
  �G��&lt;��33����QGRvW]��7;�V��K/���*�_zS�k.��%vW#l���"AJ�lG�$#H�6H�e   h5uR�A��b-K���UN�O�C��
  ��Ο��%I�%mJz0����I"K���`7Hgb��T*�J���8�܁/�Ŵ�O�O��5W���?|�yl�v�U��R��Ӵ�8�s��-���Is1_֎�W�ln��a�I��R)���=��o��b�H;&gt;yGeR�3ad�t�ȑ?=��p��d��U�.p�{w��V����X��wt�\��
  �=l��.������Z���t
  V��`Y���Z;�N��A����y�[�=�~-_;�\��`=���s�K��#�T��,b%*[�Q�H�G�)Bx���L��7|��*ZF��
  �MB���Aȅ�_L����j@oqw�N7��$� �%�U]9&amp;��Y��5��E�_CD\�E+��&lt;�    ��ٶ`�a2��p79�
  �!� N�$/�SB��J��3$���S:�&gt;K�s�sN�0O�2~���F8,&amp;����z��~7�P�y4J�
  ����0���́���B��� }姤g��Dȥ���*�M������&gt;�������S�Nz׊��J�T؋G�x"k't��n����3����h(�%�V���7V�JX���o3p���:��A+�'����~���V�8���H��V���EN��ȣ�)z��"�`
  �P��E��=�(r�"��QE.@IV�"�}S���T�QAiW�q �Wyh���&lt;4$���!��U�Z0���2ɿy�ѩ�&lt;��{�c?������+�dH������3;&gt;������u76�̋&lt;��f��0��7�L;��8����j@Yt���M��"�y5�Q!NM���{|X�#�x����ո���E�oނ�;�+�+��6+���y{���hEh$F��F��j��3�\�v���\�W��_PT0�Q�cֹP_;�c�ͨ3�|I{s�    �˥O�l2W1�8�n7;�&gt;���jqx7�=���Mpɍ��R\}hցqvA�Di�&lt;��Jlt�d5�2Eq��%�Ni�Z*���v���jF�\^_��*p�����Q7c&lt;e�wʑ�Rw�����4oiu��f_��\��h�e$� aa^&gt;֫
  �PW;���q^3:^�\����:�OF����db��F~���Vj�utt�9$�&lt;�F[��E�m��+W.�e^�t���R�O��7-޴����")�z;J�bW���*��,�}�d}BF���c����.����d�TN-:ng��|T0��,n��C�n���jD�}
  endstream
  endobj
  11 0 obj
  &lt;&lt;
  /Length 317
  /Filter /FlateDecode
  &gt;&gt;
  stream
  x�]��n� ��&lt;�,�E��؉dY�ҍ���nÐ"�a��ۇ�D�t�&gt;�|88;o������#�t�u��0��:Q�������,� �������Nd�����W�L�Bs��`�v_��gƫ�?8������&amp;m�G�w9#dl�:�۸���W��y��(��{$�h\�T���������:��R�pLF}� �����P�    K��HX1�k¶"&lt;�9aÂ��eD�#�&amp;&lt;����g��x T�ah3 cChx�2a�����m9o�������5e�8o3q�S#tsϦ�5�T2_/�K�Z��?�/�\����u
  endstream
  endobj
  xref
  0 12
  0000000000 65535 f 
  0000000936 00000 n 
  0000000887 00000 n 
  0000000993 00000 n 
  0000000169 00000 n 
  0000000059 00000 n 
  0000000612 00000 n 
  0000000015 00000 n 
  0000000286 00000 n 
  0000001283 00000 n 
  0000000398 00000 n 
  0000004412 00000 n 
  trailer
  &lt;&lt;
  /Size 11
  /Root 2 0 R
  /Info 8 0 R
  &gt;&gt;
  startxref
  4802
  %%EOF
  </code></pre>
  
  <p>It gives <code>�</code> for latin letters like ÿ ö Ú and so on.</p>
  
  <p>I want that file to stream like</p>
  
  <p><strong>STREAM B</strong></p>
  
  <pre><code>%PDF-1.3
  %ÿÿÿÿ
  7 0 obj
  &lt;&lt;
  /Type /ExtGState
  /ca 1
  &gt;&gt;
  endobj
  5 0 obj
  &lt;&lt;
  /Type /Page
  /Parent 1 0 R
  /MediaBox [0 0 595.28 841.89]
  /Contents 3 0 R
  /Resources 4 0 R
  &gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;
  /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
  /Font &lt;&lt;
  /F1 6 0 R
  &gt;&gt;
  /ExtGState &lt;&lt;
  /Gs1 7 0 R
  &gt;&gt;
  &gt;&gt;
  endobj
  8 0 obj
  &lt;&lt;
  /Producer (þÿpdfmake)
  /Creator (þÿpdfmake)
  /CreationDate (D:20140527071607Z)
  &gt;&gt;
  endobj
  10 0 obj
  &lt;&lt;
  /Type /FontDescriptor
  /FontName /AAAAAA+Roboto-Regular
  /FontFile2 9 0 R
  /FontBBox [-479 -271 1170 1058]
  /Flags 32
  /StemV 0
  /ItalicAngle 0
  /Ascent 1048
  /Descent -271
  /CapHeight 1048
  /XHeight 0
  &gt;&gt;
  endobj
  6 0 obj
  &lt;&lt;
  /Type /Font
  /BaseFont /AAAAAA+Roboto-Regular
  /Subtype /TrueType
  /FontDescriptor 10 0 R
  /FirstChar 33
  /LastChar 53
  /Widths [586 568 252 523 249 550 568 874 568 252 529 641 659 583 343 346 568 757 345 878 513]
  /Encoding /MacRomanEncoding
  /ToUnicode 11 0 R
  &gt;&gt;
  endobj
  2 0 obj
  &lt;&lt;
  /Type /Catalog
  /Pages 1 0 R
  &gt;&gt;
  endobj
  1 0 obj
  &lt;&lt;
  /Type /Pages
  /Count 1
  /Kids [5 0 R]
  &gt;&gt;
  endobj
  3 0 obj
  &lt;&lt;
  /Length 218
  /Filter /FlateDecode
  &gt;&gt;
  stream
  x­Ò=NÄ0à~N1Àñ¼ÿIbl
  òH6A¬Äù×©hH,nÆúôüFØ·s·]ÙÄåÂÓ'
  óÏÇ4¿O&lt;­´
  x^§/Î«ðûJ}ÓOÌsÊÅ©×
  ÏÂ®ÝC(áë*½üÑ"ÂØKÙûXDêsYÌd³f¼aìÅ&amp;§b8H9á¹á@|Ñ´+,­È¤ãö}dxu%ÇÃõÑ¶­ME7S½óóAXUmÝjÀøËÞxWÏ¿
  endstream
  endobj
  9 0 obj
  &lt;&lt;
  /Length 3042
  /Filter /FlateDecode
  /Length1 4920
  &gt;&gt;
  stream
  xX
  pSUö?÷¾¤iÚ&amp;MÓR4ÒýHÛ´TÊ ¥ (P*´|I·¦MhmSÒ`ÛÑf][lª¨CR».*®­#ÒuÔÅÿºCÑYgÝÔsß{)IqÖdÞËûûÞ9çwî9çÞ ù°îohq´6 ä&lt;r»6\Iû)^ =ÚìipdÌOoHð¡,¯©Å×y_aÜaÄ/ ^ÓÔär$ÄrÄ£ïhqt¶Ñ
  ® ÑØÜæi÷ÑJnâ2Ä­WÃ«ô÷ðmø¸sgËÞW8³ð ÀIj¦g
  Åccøka·Jwfàp·àØÀ×øEÛmQ;w­8@Ôê×d¯±»íÇµ~2_@,z«ÞRlá»Ã9Áp.ß,¯_ûe½=Ì¬8   *¿ÁvSFQ­B bªÐ!Ð1ÀéÚvlRfÍ²¦Ñ\Q¦5CTáTßy°áwíÞ;³AîHåêás¡uôð#ÛÍ½)ô£#N¼âÝ,EC4â fêü3zî¶/×D~Ü~~Mé­Åvââ/%Æ!_ãØen¯,xXÖÊâ"Ó¤¡æSZ&gt;yöàÓl­}íuÓéWë7é\T8ãtþÄá´DR; Åâ&gt;j8MçÏ2´A`ÚÍ1NQfVffqJe"dLI5¥¦SDkFfI=5Õ^8ã¾?2øÖyè¨woX÷Ø.8ûHO½õî^^Ý·uÇy\\´y}yÙ=i9{·îød·èvÔ`&lt;7"ç³²Á#³D'GXK©ÒHp´âd_k&lt;©=«EcØ
  ¤LÖ²qÌ0w³VÈ¦iÉÌÌÆÔ^,Ó´feÊ|§Î*)¹sÓ5ñ¤$°áHàÆß&gt;÷m¬ë8AÅËoÑêBßm::å=ë
  dVº_Ù·ÿØ¦:cøÀ©7ý¡ÿ6íi]äï¼wqu$¹ò5À]2[9ñ1Ùjêu==¼.3W¦[3ÌKu°éØ;ÁÍ¾íYbÏ­ª;óy¨êé\±hô2_ñEô /ÖHäc|Ñ ÐD5$F`RXXÐè¨lC§Ó~Áé®O$Q|°¹yýpÛï[[\¿?½yã:_:ê^Vãt®oþú¡.ºëÙ»7©C÷Ò]û¸§bô&lt;²£Ð¾Üô52;Éí_d'õ
  õÄþ¨£8`Ã!bêd±Æ!ñHÖË¢ÒKµQÌÏ  :÷÷¦p&gt;ùDMç´i«wï!?^
  _¨¨]þwåð»áëÇ¯,«]«Xræy6/7{Ì$Àîú6ÊÚë!¬H=©kè
  rME®÷Ë\%F{Ò@&lt;¨XYÄÛãGâiíÀ³ñØ@ÐEñTé¦(?¶ÅÅE|FJ¢ZbE,XC´ê«ð5b8ñ÷Ð|Û·Ë¹·dYéÛ/6ìÖQòÃCFû}Î¿=üß/]¸möRîCS|l¥£0=þ#\;4X!óe.ÒDV0.@8ÆløØIJ$¶òÆÞ:Í3d!]A{Ðpøbxizª·¯/¼.üßzÿÊÓý]]8
  /Ñ8ôeìd&gt;âËx¯'º&amp;Ê    hOùv½Åz£,ãá£ÖArÜNÖ_
  uýú/~(øÃÏ/½&gt;7vÍðÐÇD#Õ)ó£Còã÷]áf©FV ­jl÷gÙ)]M63¸yð¤ú¬n§&amp;Þ;]eCýì´_U©1±§êØÉ'¿ZØcâ*-ÔFÞÂëCMAî½¥ûèÐCX#÷ú2ædÌýÔ"ÐF@`aÔêü$²dö~BÙB¥¬ÎJË =®ÊMiA¿!ïÑ5©Ó¸Ý"Öü
  ¾ô@õoT¼²ÿ»L7
  óÀ÷FÍZÄ1$)S½z&amp;éê¨Óù
  Ãþ¶CÑÛV\´g[Ëõ¤ïÌyEúº)©5ÙÝG
  óÂ7zC¥sÕâ£É¦'÷Ó'{Àü£Põz
  +õ¦*ÀÈÜºi±Ò6@ª}ÎÌ¯´%.m1¤ÅÛeoõÒúV~¨®¯(ø©øé
  §G&lt;±¦33³«¦ûQGRvW]ùÓ7;VôK/«*_zSk.ð%vW#lÿµõ"AJÌlGÈ$#H6HÃe h5uRÝA¢b-KªªUNOµCõ
  ¥¼ÎÒ%I÷%mJz0éñ¤ýI"K½Ä`7Hgbå²T*ÎJìä8õÜ/ÒÅ´OO÷ÿ5WÌþ¸?|úylûvêUõöRÿÓ´ï8ùs¨-îÄIs1_Ö×WÌlnÙáaäIô¾R)¤è=­Îoö§bÞH;&gt;yGeRÉ3adtáÈ?=±pæ¤dûÔUÕ.p{w½òV¼æ¼ØX¿«wt\ÿâ
  ¬=lã.¹³ñZÏt
  VÙð`YåõZ;ÙNúîAç×Åy´[µ=Ú~-_;°\½`=³µsØKÍÒ#Tô,b%*[¦QHG)BxúöðLÁü7|ÿõ*ZF«È
  ßMB¯ÞAÈ½_LÅÜ×Âj@oqwëN7ÒÎ$ %ÿU]9&amp;±YÕá5ÛÝEÇ_CD\ÐE+ë¸&lt;Ú    úøÙ¶`ða2ýÛp79ô
  ù! Ní$/SBÊûJ´Â3$¿ÝäS:&gt;Ks·sNî0Où2~ÿ­°F8,&amp;«Ðýzï~7ôPúy4J²
  °ÉÄ0ôÍÁÂBäÀ }å§¤gëÅDÈ¥ïÁ*MÁàº&gt;ô¾¦æÍSÿNz×þ¤JTØGÊx"k't¿ônÆÞÇð3¶h(%°Váý°7VÁJXÁo3p´Á:¸ßA+¥'¦¹ã~¤ãVø8üH¡VÓENñíÈ£È)zù"ç`
  ìPäÁEÎã=(r¦Â"ÐëQE.@IVä"Ç}S¬TîQAiWäq WyhÉë&lt;4$¨Èã!UäZ0¯¹2É¿yäÑ©&lt;ÖÓ{Æc?¾¤È¡+òdHäî¸ËÓê3;&gt;¹ÁÓÖåu76ùÌ&lt;Æf¹0¿ 7ÿL;¾ö8Á¿¼j@YtÜÐMÒè"y5Q!NM®ðÔ{|X#õxøÀ³ÂÕ¸¥ÙáEoÞ·;À+Û+ï6+·¢y{ÚÒhEh$FÊFí±jþ×3«\Þv·§Õ\W_PT0Q¶cÖ¹P_;cÔÍ¨3|I{sÆ    ÚË¥O¶l2W1©8àn7;Ì&gt;¯Ãéjqx7=¸æMpÉ¦ÌR\}hÖqvADiÊ&lt;øçJltód5Ñ2Eq§%öNi¦Z*¼îvÛÑjFÏ\^_»§*pÚØôµ£Q7c&lt;e·wÊûRw«µÝå4oiuº¼f_Ë\ÞæhÀe$Ç    aa^&gt;Ö«
  ºPW;¨q^3:^\å:¼OF±Ïä dbôF~Ï×Vj³uttä9$ò&lt;ÞF[³ìE»méÝ+W.Ìe^°tô¡RüOÇÒ7-Þ´½")Úz;JbW©À¶*±ã,Ä}d}BF±êÁc¦ñ£.éÿ®ÁdµTN-:ng¿§|T0ú,n½ºCªn¥ßýjDú}
  endstream
  endobj
  11 0 obj
  &lt;&lt;
  /Length 317
  /Filter /FlateDecode
  &gt;&gt;
  stream
  x]Ínë ÷&lt;Å,ÓEäßØdYªÒ··ºnÃ"Õa²ðÛD©t¶&gt;à|88;o³²°¨#ëtÀu¹0áÅ:Q ­¿Õ,½ ó¸­çÁºNdÿÒòÃ»W½LøBsÆ`Ýv_çgÆ«÷?8£¾&amp;m÷Gúw9#dlÝ:­Û¸íëWñ¹y({$µh\½T¤» èò¼ïé:ýßRùpLF}Ë º²èúP÷  KÂæHX1kÂ¶"&lt;9aÃ°eDÂ#£&amp;&lt;±µgáÄx TüahÂ3 cChx2açm9oÛÞó­â¼5e¨8o3qS#tsÏ¦Õ5T2_/·K½ZÏ?À/\üÜÿu
  endstream
  endobj
  xref
  0 12
  0000000000 65535 f 
  0000000936 00000 n 
  0000000887 00000 n 
  0000000993 00000 n 
  0000000169 00000 n 
  0000000059 00000 n 
  0000000612 00000 n 
  0000000015 00000 n 
  0000000286 00000 n 
  0000001283 00000 n 
  0000000398 00000 n 
  0000004412 00000 n 
  trailer
  &lt;&lt;
  /Size 11
  /Root 2 0 R
  /Info 8 0 R
  &gt;&gt;
  startxref
  4802
  %%EOF
  </code></pre>
  
  <p><strong>C# CODE</strong></p>
  
  <pre><code>    public FileStreamResult GetFileStream()
      {
          string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
          string fileName = "template.pdf";
          return new FileStreamResult(new System.IO.FileStream(path + fileName, System.IO.FileMode.Open), "application/pdf");
      }
  </code></pre>
  
  <p><strong>JAVASCRIPT CODE</strong></p>
  
  <pre><code>function ajaxFileStream() {
      //jQuery.support.cors = true;
      var url = "/Home/GetFileStream";
      $.ajax({
          type: "GET", //POST
          url: url,
          crossDomain: true,
          //data: {},
          success: function (response) {
              console.log(response); // here i get STREAM A 
              //do some operation on response
          },
          error: function (error) {
              console.log("error");
          }
      });
  }
  </code></pre>
  
  <p>Is there any change in <br>
  <strong>Server Side:</strong> while streaming the file in some charactertype like utf-8 or something orther. <br>
  <strong>Client Side:</strong> some function code in javascript to convert from <strong>STREAM A</strong> to <strong>STREAM B</strong></p>
  
  <p>Any suggestions are welcome, Thanks in advance.:)</p>