问题描述:

excuse my bad English.

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

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óø

áÕª[email protected]¥£Ç~9<<üÓÖnµ¦TÂÒSò ù`q19FÀty-Wb-®ÂÛbêÙ="iî1c-c.5JTÝY¹Qj

ø$ÃúìRTQÕ±bÅ#5kdë(ãûÅÅg-"Ì=rÒîÕ}Ë´+éÁt½¼ÒÑÆZ9iæÅÈpýúõv»MqÀú

ѯ¾ÿé¤j«*[email protected]å~7®ohA÷¾º³#¼ða.l-+M½MÝÈ°vãäöë4ú³æƤD~:¯LÓZä8áûÙhFr>+ú(JXËf^°,ÃÒ2F6ùÉ+fÅ)¡Ö¤1Æ'uÖX¿XÕN1ú*« øZ`

+!^Ãzã7L aüMÇG¹q¿ ]~)\õ+I&%0È9£UdyB|e¡£¬a½¥ Ìäú' ¿6¾­¨¹£ ¬a¥ÉaötOþ¸lBFɶ¬S?I­<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¯±^Ï'¦^&°æ³ª

ÈAa'RøÅ[email protected]@ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔX+¢ôéóJ1æcíÁeúIfÊ5l¶É/v}xZùü<}~)Ù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>ÜÁüÊè6ëVÉ©q±ÁûÇZ]ÒR=ÆI,ô0^1F ñNä«NJýr"½±Nýëß7ÚQ|¼´ôÃ~ÿMË/6,ÞCGYF¹ZÆ©à1¿VPaVèâTz<çô¡~¦~ÏûðÛ» 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>-S¨Ki©N­ÃO®=¹þÌ×Wã÷úý÷£h~4z!>3ìÞ¸1iµÎF¿Á!(2I

ý/?®F÷ÚkDÔé<¹Wt: £Ñ&ýáðÖw°N2¥ÝTHð_ÃoM§ûQ4ßnKïv%¢Á`t¥u'¯u` !Z2ñ XW£{7oÞ¢£ôjsó¿Îv¯·3,/?½´Ô¢£å-gÀJ§WÉ£n÷_ãñt4ú²ß@D½Þ"mn~raï[email protected][

Ç'`)éÕx<M¾£h~uõ<õûïç´o%ûu'!Åüjì§Ô[xiùõ§ÝE<ÿ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&«]ÞãÐ[ÀºÒº³zó­­-$'/^<U¾×[ìt¶Ñ¨ýÒߦ/ø¨ 7"9}䤫4ÉéA&©å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¤µ

X vf1ÊI'ÕéË© ֵת®÷y?ÂÕ

öósAM

/aê8dXñ¯20éxÃpø°×{÷oþØɸt/J_ôi¹>¬ãH

èC¿Ï %;iØc,£Ì¬>d`úB+ú-7}Æi>®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&VWÿ1ôû?HÞ14ríÚùáðÉä˯ÆïI¶87+{¬Û ZiÉBQéZÆ3V(º$í´Bh'o¤ øyC²ÍZKØËV]ƶj¤¿óÒÂ|CÞñn©b°íAàÖ½Ûãñ Ò«/§Ó"ò«Õ:Õí>Ûëí £ÑKÖ_qÐ;F9HdädÕJÎ('öHPÞ@ýfmp([{CEJ´[ûT¯bl=Ö²¶Ý¯%ökÉ\×dz??ûÁ¬áð Ò+"zåsÃáÓéAü»}<íö¹áðáööþhôñSK¥÷s0ÝÊeômÄjS&m¡¤ [email protected]¢« Úå}*¬Å+cl»®Âc

³]«a¼vNöäg.` W¯(æ77/O&$ûhuõ|¯·3oÿh+¦DnäB1Ú#¹q«¡ì×SÐ%7×îݧ4Ç ùHpˤur9ÏKʳïàÝ[­3D´·÷?¡,a´"¢ÝÝGÂ1Aî Õé·,&¿ãËä1;IìaT¬y+WxÃCläl»[email protected]\¼Î5*ÒÆ a-/_>î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&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Â<(«SéøÄÍ(_¾Ëè±<Û®_ùç%ËóòÚõDI·º0ÓLCÖ8.­r$CS"'ëμîò²qÖ´N¿ø [íäKØö<zó'>Aú ̳°\×hÊ×Åǹ"á4M^ØI²~mW\W(Y9)Ò«R¿m

In¯çkµA9È §2ë©÷ù²²ãwefµ(gÛé_Î+TÄx&>PlÎZèe2Ó~7ÖW©Ö3^×ÔçVéõ

ôânÀ|A1ÞÉ^;ãôì[ØvÅ«~63ºxíJ/ëe²lF¶U¤ù¹Ö`DήËÞ軳"ùà¼NX¸0f

×iiqÚQ¿[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ,@[email protected]ÀÔ'?/ó7W¡ óÚk¯½óÎ;ÉÇÇÖ믿^= åqõöÛoÏÍÍUk

ð<ΰ­³ÏéÃÃÃôçëׯWe

ðÌ)ëöíÛU<ØÖ¨

ÿ/æ7JãpTÙIEND®B`

Here my code

The index calling ajax

index.html

$(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();

});

});

The Ajax

 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');

}

});

}

The controller

function requerimiento(){

//Variables

$usuario = $_REQUEST["usuario"];

$maquina = $_REQUEST["tipo_maquina"];

**...**

$pdf = new PDF('P','mm','A4');

$pdf->AddPage();

$pdf->SetFont('Helvetica','B',16);

$pdf->Cell(190,10,'Detalle del Requerimiento','B',2);

$pdf->Output('I','requerimiento_pdf.pdf');

/*

header('Content-Type: application/pdf');

header('Content-Disposition: attachment; filename="requerimiento_pdf.pdf');

*/

}

网友答案:

In php

header("Content-type:application/pdf");

and after

$pdf->Output('I','requerimiento_pdf.pdf');

First you have to set header. And only after that output document.

相关阅读:
Top