Jquery codeigniter dompdf ajax未保存pdf
我面临一个问题,我已经成功地使用dompdf生成了PDF文件,但它没有显示在浏览器窗口中,当我尝试使用firebug进行调试时,它会显示以下PDF格式的数据Jquery codeigniter dompdf ajax未保存pdf,jquery,codeigniter-2,dompdf,Jquery,Codeigniter 2,Dompdf,我面临一个问题,我已经成功地使用dompdf生成了PDF文件,但它没有显示在浏览器窗口中,当我尝试使用firebug进行调试时,它会显示以下PDF格式的数据 %PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pag
%PDF-1.3 1 0 obj << /Type /Catalog /Outlines 2 0 R /Pages 3 0 R >> endobj 2 0 obj << /Type /Outlines /Count 0 >> endobj 3 0 obj << /Type /Pages /Kids [6 0 R ] /Count 1 /Resources << /ProcSet 4 0 R /Font << /F1 8 0 R >> /XObject << /I1 9 0 R >> >> /MediaBox [0.000 0.000 612.000 792.000] >> endobj 4 0 obj [/PDF /Text /ImageC ] endobj 5 0 obj << /Creator (DOMPDF) /CreationDate (D:20120710102754+00'00') /ModDate (D:20120710102754+00'00') >> endobj 6 0 obj << /Type /Page /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj << /Length 400 >> stream 0.000 0.000 0.000 rg BT 34.016 719.095 Td /F1 24.0 Tf [(Darksiders II)] TJ ET BT 34.016 683.969 Td /F1 14.0 Tf [(Panda)] TJ ET BT 34.016 653.268 Td /F1 12.0 Tf [(2012-07-04)] TJ ET q 48.000 0 0 48.000 34.016 586.457 cm /I1 Do Q 0.500 0.500 0.500 rg BT 34.016 627.257 Td /F1 8.0 Tf [(Image not readable or empty)] TJ ET BT 34.016 617.257 Td /F1 8.0 Tf [(media/stats/images/a:2:{i:0;s:36:)] TJ ET endstream endobj 8 0 obj << /Type /Font /Subtype /Type1 /Name /F1 /BaseFont /Times-Bold /Encoding /WinAnsiEncoding >> endobj 9 0 obj << /Type /XObject /Subtype /Image /Width 64 /Height 64 /Filter /FlateDecode /DecodeParms << /Predictor 15 /Colors 3 /Columns 64 /BitsPerComponent 8>> /ColorSpace /DeviceRGB /BitsPerComponent 8 /Length 929>> stream h�՚�n�@���T�R�#���.�"Z!�����P���\!W[M�.����]�,��*@ș��������3�����6��n�O�M]�#����|֯/����D4�I��LJ�pEQ�$UUM\UU�e�l6�O~C�8��|��DD��>�cD�>5��������k�~�gߴZ� ���bQŤ4QY���g����$��"*�b�X�Z�ડ,���#'I�N�O�� b����nD?Q�睑����Q���j+��z�6Xfp�����{��3w@#��k�!�<�<�TU�~�����r��R�y�{���`/��1˲p9��k�8��~�slp�W?��4ǽ��3VI܂�LY� �ӮY���"��|���@p�>9=,k[��;�� u]ߝsl�M��%p����fE��^`\�%=��["�e^b�-�|CHcS[뺶��,���õ��O�n�K�Tv���i don't know if you have considered it, but can you use get_pdf to forcedownload?
http://codeigniter.com/user_guide/helpers/download_helper.html
another option is to use the dompdf to create a temporary file, then create an anchor to that file.
in your get_pdf: echo json_encode('html'=>$anchor);
then your .ajax success handler, can have something like:
success: function (data){
try{
var json = $.parseJSON(data);
if(typeof(json.html)==='string'){
$(<selector>).html(json.html);
}
catch(err){
.. handle errors ...;
}
}
%PDF-1.3 1 0 obj>endobj 2 0 obj>endobj 3 0 obj>/MediaBox[0.000 0.000 612.000 792.000]>>endobj 4 0 obj[/PDF/Text/ImageC]endobj 5 0 obj>endobj 6 0 obj>endobj 7 0 0 obj>stream 0.000 0 0 0 0 0 0 0 0.000 0 0 000 rg BT 34.016 719.095 Td/F1 24.0 Tf[(暗色器II)]TJ ET BT 34.016 683.969 Td/F1 14.0 TfTJ ET BT 34.016 653.268 Td/F1 12.0 Tf[(2012-07-04)]TJ ET q 48.000 0 48.000 34.016 586.457 cm/I1 Do q 0.500 0.500 rg BT 34.016 627.257 Td/F1 8.0 Tf[(图像不可读或为空)]TJ ET BT 34.016 617.257 Td/F1 8.0 Tf[(媒体/统计/图像/a:2:{i:0;s:36:)]TJ ET endstream endobj 8 0 obj>endobj 9 0 obj/ColorSpace/DeviceRGB/BitsPerComponent 8/Length 929>>流h�՚�N�@���T�R�#���.�“Z!�����P���\!W[M�.����]�,��*@ș��������3.�����6.��N�O�M]�#����|֯/����D4�我��LJ�佩克�$UUM\UU�E�l6�O~C�8.��|��DD��>�光盘�>5.��������K�~�gߴZ� ���bQŤ4QY���G����$��"*�B�X�Z�ડ,���#'我�N�O�� B����nD?Q�睑����Q���j+��Z�6Xfp�����{��3w@#��K�!� 我不知道你是否考虑过,但你能使用get_pdf强制下载吗?
另一个选项是使用dompdf创建一个临时文件,然后创建该文件的锚点。
在你的get_pdf:echo json_encode('html'=>$anchor)
然后,您的.ajax成功处理程序可以有如下内容:
function setup_fancybox()
{
$('a.fancybox').unbind('click');
/* Apply fancybox to multiple items */
$("a.fancybox").fancybox({
'transitionIn' : 'none',
'transitionOut' : 'none',
'speedIn' : 200,
'speedOut' : 200,
'overlayShow' : false,
'width' : 650,
'height' : 800,
'onComplete' : function() { parent.$.fancybox.resize();},
'type' : 'iframe'
});
$('a.fancybox').click(function(){
return false;
});
}
PDF over AJAX很难,但并非不可能。我想问的第一个问题是:为什么要在AJAX上这么做?你的工作流程是什么?你是说你想让用户点击一个链接,然后让浏览器弹出一个对话框来保存PDF?如果是这样的话,我就不需要AJAX了。