title: I cant generate pdf with fpdf and ajax
body: <p>Excuse my bad English.</p>
  
  <p>I have a problem, I try to generate a PDF file with the fpdf library in a php (controller) passing before by an AJAX (jscript), but it does not generate the pdf but it generates this</p>
  
  <pre><code>PNG
  
  
  IHDRd'©ñ :IDATxíAÇßFÊÆ
  (l£Mb1ö`á\6ÓÆí!°gÉ-Ö$\Ârçl4öÁø0"¶7Y#´'BwQÌ
  áY¬Äe1rÍ¡µ­ÞªêW¯ª«»§·ÿcõôT½÷êUõëWÕÕ³s³Íááa|ðjí9§ãÖ4îß¿_µ    ¨\¸p¡jf¹¹¹ôÇÓDô""zóø
  áÕªM@¥£Ç~9&lt;&lt;üÓÖnµ¦TÂÒSòù`q19FÀty-Wb-®ÂÛbêÙ="iî1c-c.5JTÝY¹Qj
  ø$ÃúìRTQÕ±bÅ#5kdë(ãûÅÅg-"Ì=rÒîÕ}Ë´+éÁt½¼ÒÑÆZ9iæÅÈpýúõv»MqÀú
  Ñ¯¾ÿé¤j«*!@å~7®ohA÷¾º³#¼ða.l-+M½MÝÈ°vãäöë4ú³æÆ¤D~:¯LÓZä8áûÙhFr&gt;+ú(JXËf^°,ÃÒ2F6ùÉ+fÅ)¡Ö¤1Æ'uÖX¿XÕN1ú*«øZ`
  +!^Ãzã7L    aüMÇG¹q¿]~)\õ+I&amp;%0È9£UdyB|e¡£¬a½¥ Ìäú'¿6¾­¨¹£   ¬a¥ÉaötOþ¸lBFÉ¶¬S?I­&lt;4ób+o×¬+DÊAfõhUÄev¨ò¼É·ÉGö¬Z9iêÅhVVz¼f]!É±±þ­U"×åñ¤7ÞvRÅieØÏá·^g-f^ð°5¬2ÓL©Ârâ¨§   xJxB 4*TÅ4ób5¬B2¬2¯±^Ï'¦^&amp;°æ³ª
  ÈAa'RøÅQ@m@ÀÔ,@m@ÀÔ,@m@ÀÔ,@m@ÀÔ,@m@ÀÔX+¢ôéóJ1æcíÁeúIfÊ5l¶É/v}xZùü&lt;}~)ÙFéºé
  GãI¨Ic£ ®:å¥fXåG+W¥ÆlK¿-èÅÒg²j¥IznåRÄ¢%»êÒR%y¢öPöxøGÞvW9m®º¬c#Ëå8T-I¿AÍ°fÄÉ­ÜâÊeÒ¯Ò:FáFE®­¤¤íIk4O·ÇØ.«ÍúU²ÑÖ2
  [ªgÀsü81']JKí2jw­%ìÁ°®´îìîþçìÙ3wéÅ ü¯×Òc:z¨hg$[C¡R2&gt;ÜÁüÊè6ëVÉ©q±ÁûÇZ]ÒR=ÆI,ô0^1F    ñNä«NJýr"½±Nýëß7ÚQ|¼´ôÃ~ÿMË/6,ÞCGYF¹ZÆ©à1¿VPaVèâTz&lt;çô¡~¦~ÏûðÛ»FDtñâVëÔx¼Õí¾Â0ÂN¡FèªÆ0AD.ÙÉØ-ÆA/ôXÛ»W¢PÕÂsvVWXÕÊaõû$¢µµ¨ÓYØÞÞ¿víãñV{ûÃ¯/þ4yæ»7åéÔ($íÇà÷Õ¢%3¤µÝXÆ*ÙÏÒ,ñ^FèCIKõ±aÕ.!T/gy&gt;-S¨Ki©N­ÃO®=¹þÌ×Wã÷úý÷£h~4z!&gt;3ìÞ¸1iµÎF¿Á!(2I
  ý/?®F÷ÚkDÔé&lt;¹Wt:£Ñ&amp;ýáðÖw°N2¥ÝTHð_ÃoM§ûQ4ßnKïv%¢Á`t¥u'¯u`    !Z2ñXW£{7oÞ¢£ôjsó¿Îv¯·3,/?½´Ô¢£å-gÀJ§WÉ£n÷_ãñt4ú²ß@D½Þ"mn~raïv@[
  Ç'`)éÕx&lt;M¾£h~uõ&lt;õûïç´o%ûu'!Åüjì§Ô[xiùõ§ÝE&lt;ÿvÂ¸wÄ»×ªm+y¬-bòø¬¬Õ+":{öñ*~§µZ§¶¶|sûCoãV^Ë¨v×LC(m5*kÛaèÛÖõQW¹Q¯v9?%¼Ýkß¼EGëDEóÉ·­Ö©ä Óúýýþû£Ñåü[ÒnUv]é«²`1àí'Nº²jåÌÒðöl¬¢ï÷ÃìÝ4½í~ö0ÝÇqc­ÅTÔÛ¥û'½C«YþqêwI-ïqhÅ9`ÅéÕÒRkyùéøL¤VWÏß¼ùEð-+Ç_,0vq¸óÛF]tÜûë/åzHØ®nµGâ%k+þwÅ¨ËolHòw«½ccµi¬µÿóþ´7&amp;«]ÞãÐ[ÀºÒº³zó­­-$'/^&lt;U¾×[ìt¶Ñ¨ýÒß¦/ø¨ 7"9}ä¤«4ÉéA&amp;©åasúVÌGyå@×ÊcýÆ±5]ÊÌ?å+W?;¡Á8ÊCi    ãPÇ-`
  £8½7.è¤§D§½Þ»/wûþf²½ÿoÌ·CáaÄo­·t¦V~í*ýîRVê/??K.0BÇ¡Ã¢ûÖÑèc:^Å$ñ+¾¥|oq·rnqðk¤µ
  Xvf1ÊI'ÕéË© Öµ×ª®÷y?ÂÕ
  öósAM
  /aê8dXñ¯20éxÃpø°×{÷oþØÉ¸t/J_ôi¹&gt;¬ãH
  èC¿Ï%;iØc,£Ì¬&gt;d`úB+ú-7}Æi&gt;®el;sÆ¨]Çê­Ç7£KJöè÷BÇ¡éËÏWZwÚíßÑ`pQXýþáð!ýlòítzÐnßNºÝ=µôso[AÓp(1«G·äågéO¯Z­ÇÚÂÂ¼éÛSñÓÁ`ãjtÏËlÐ Vv#QÀbV¯b8¥,º'¬®¢ùét0Øð²4u¯×ªÝ(`ÅéUòV³NVJ¯¾Å¯8ü°¬$½J¶¶ëdíMì5íõÞu0°¬øWbÚísLìå#WòòoqÈ"çÓBûé*Í¤Ó_V,Ì¨Ê¨¼QÆÞVYûÉ¬ÄKuaïöææ'tügEln^^`v½QÍ¯­E$KÓ3²üü¶YæÑ÷ßÚ
  í±ìÃºqcléM&amp;VWÿ1ôû?HÞ14ríÚùáðÉäË¯ÆïI¶87+{¬Û ZiÉBQéZÆ3V(º$í´Bh'o¤øyC²ÍZKØËV]Æ¶j¤¿óÒÂ|CÞñn©b°íAàÖ½Ûãñ  Ò«/§Ó"ò«Õ:Õí&gt;Ûëí£ÑKÖ_qÐ;F9HdädÕJÎ('öHPÞ@ýfmp([{CEJ´[ûT¯bl=Ö²¶Ý¯%ökÉ\×dz??ûÁ¬áð  Ò+"zåsÃáÓéAü»}&lt;íö¹áðáööþhôñSK¥÷s0ÝÊeômÄjS&amp;m¡¤S@¢« Úå}*¬Å+cl»®Âc
  ³]«a¼vNöäg.`    W¯(æ77/O&amp;$ûhuõ|¯·3oÿh+¦DnäB1Ú#¹q«¡ì×SÐ%7×îÝ§4Ç  ùHpË¤ur9ÏKÊ³ïàÝ[­3D´·÷?¡,a´"¢ÝÝGÂ1AîÕé·,&amp;¿ãËä1;IìaT¬y+WxÃCläl»k@\¼Î5*ÒÆa-/_&gt;ît¶ùg®L§ÛÛû±ü¯Ùé4÷|¦ÏMøDW×eD¥ro¹d=B]:y#T´¶êeaYû]Òf¬*JÐ;~p/?_îu»oÅëîÁY]ýÉ÷^ùUd1TE    =ÒNC¡è/?4yîån¿KßÛÛkÄÂÂwBýi)óÎf&amp;wºý÷°îÒt6°ÖûS{ ¡C¶.×5Mîtÿ?U%¨
  ÎæëÄà½¯ uYOôZÆMÌp£aó=u+\    öSÝ¥ë°§ÏïÒ3%QR§·¡4f}¥?ïËz(Rd¿ºräUf$RT»8¡N   Ë¼Òã?{¢lÌ*ìdI´n\Ñ~bERFX¿ôo³v6ëÙ¯](ÇZFâyÒlôüàNö;£9CUÜ½3=%Ô³äf¨lqTÊëÅô«.£IÂ&lt;(«SéøÄÍ(_¾Ëè±&lt;Û®_ùç%ËóòÚõDI·º0ÓLCÖ8.­r$CS"'ëÎ¼îò²qÖ´N¿ø [íäKØö&lt;zó'&gt;AúÌ³°\×hÊ×ÅÇ¹"á4M^ØI²~mW\W(Y9)Ò«R¿m
  In¯çkµA9È§2ë©÷ù²²ãwefµ(gÛé_Î+TÄx&amp;&gt;PlÎZèe2Ó~7ÖW©Ö3^×ÔçVéõ 
  ôânÀ|A1ÞÉ^;ãôì[ØvÅ«~63ºxíJ/ëe²lF¶U¤ù¹Ö`DÎ®ËÞè»³"ùà¼NX¸0f
  ×iiqÚQ¿Ew@cAÀÔ,@m@ÀÔ,@m@ÀÔ,@m@ÀÔ,@m@ÀÔ,@m@ÀÔ,@m@ÀÔ'?/ó7W¡ óÚk¯½óÎ;ÉÇÇÖë¯¿^= åqõöÛoÏÍÍUk
  ð&lt;Î°­³ÏéÃÃÃôçë×¯We
  ðÌ)ëöíÛU&lt;ØÖ¨
  ÿ/æ7JãpTÙIEND®B`
  </code></pre>
  
  <p>Here my code
  The index calling ajax
  <strong>index.html</strong></p>
  
  <pre><code>$(document).ready( function()
     {
          //RESET MODAL CONTENT
          resetModal("#myModal");
  
          $("#btn_pdf").click(function(event) {
              pdf_requerimiento("usuario", "tipo_maquina", "patente", "codigo_codelco", "hr_inicio", "hr_termino", "fecha", "hr_solicitud", "hr_operador", "hr_gps", "rendimiento_gps", "rendimiento_operador", "rendimiento_maquina", "rendimiento_usuario");
              event.preventDefault();
          });
      });
  </code></pre>
  
  <p><strong>The Ajax</strong></p>
  
  <pre><code>    function pdf_requerimiento(usuario, tipo_maquina, patente, codigo_codelco, hr_inicio, hr_termino, fecha, hr_solicitud, hr_operador, hr_gps, rendimiento_gps, rendimiento_operador, rendimiento_maquina, rendimiento_usuario) {  
          form = new FormData();
  
          form.append("action", "pdf_requerimiento");
          form.append("usuario", usuario);
          form.append("tipo_maquina", tipo_maquina);
          form.append("patente", patente);
          form.append("codigo_codelco", codigo_codelco);
                    **...**
          $.ajax  ({
                  data        : form
                  cache       : false,
                  type        : "post",
                  url         : "pages/pdf/controller.pdf.php",
                  processData : false,
                  contentType : false,
                  success     : function(data)
                  {
                      /*window.open(
                      'data:application/pdf,'+encodeURIComponent(data)
                      );*/        
                  },
                     error        : function(data){ alert('Error');
                  } 
     });
  }
  </code></pre>
  
  <p><strong>The controller</strong></p>
  
  <pre><code>function requerimiento(){
          //Variables
          $usuario = $_REQUEST["usuario"];
          $maquina = $_REQUEST["tipo_maquina"];
                       **...**
          $pdf = new PDF('P','mm','A4');
          $pdf-&gt;AddPage();
  
          $pdf-&gt;SetFont('Helvetica','B',16);
          $pdf-&gt;Cell(190,10,'Detalle del Requerimiento','B',2);
  
          $pdf-&gt;Output('I','requerimiento_pdf.pdf');
          /*
          header('Content-Type: application/pdf');
          header('Content-Disposition: attachment; filename="requerimiento_pdf.pdf');
          */
      }
  </code></pre>