fpdf输出无法加载到浏览器中。

i am trying to create and download pdf from html table using fpdf in my wordpress plugin. output shows similar to the following lines in console instead of open pdf to my browser.

%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�{

i have sent data to actionpdf.php using jQuery. here is my jquery script to send html table to actionpdf.php

    jQuery(document).ready(function(){
        jQuery('#btnPdf').on('click',function(){

                $.post('".plugins_url('',__FILE__)."/html-to-fpdf/actionpdf.php');

            });
        });
    </script>

and here is my action 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;
?>

what i am doing wrong? i am stuck on that.any helps are welcome.

Probably you have to set the content-type to "application/pdf" to make it working as expected.

Try setting contentType to 'application/pdf' in the ajax call

http://api.jquery.com/jquery.ajax/