我正在尝试使用我的wordpress插件中的fpdf从html表格中创建和下载pdf。输出结果类似于控制台中的以下行,而不是打开pdf到我的浏览器。
%PDF-1.4
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 502>>
stream
x����o�0���+�q����&}�Z���N�f�[L%ai������E����gߙ��A�������@�#j
�"a����W�{我已经使用jQuery向actionpdf.php发送了数据。下面是将html表发送到actionpdf.php的jquery脚本
jQuery(document).ready(function(){
jQuery('#btnPdf').on('click',function(){
$.post('".plugins_url('',__FILE__)."/html-to-fpdf/actionpdf.php');
});
});
</script>这是我的操作pdf.php-
<?php
require('fpdf.php');
$pdf = new FPDF('P','mm','A4'); //with page settings
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!',1);
$pdf->Cell(60,10,'Powered by FPDF.',0,1,'C');
$pdf->Output('sara.pdf', 'D'); //force download file
exit;
?>我做错了什么?我被that.any卡住了,欢迎帮助。
发布于 2015-12-09 17:06:30
可能必须将content-type设置为"application/pdf“才能使其正常工作。
发布于 2015-12-09 18:04:22
尝试在ajax调用中将contentType设置为'application/pdf'
http://api.jquery.com/jquery.ajax/
https://stackoverflow.com/questions/34174382
复制相似问题