Some data has already been output, can’t send PDF file – fpdf issue in WordPress


I encountered a problem with FPDF in wordpress. Actually, I am developing a wordpress plugin where need to generate pdf. As a php application its working fine. But when I converted it to wordpress plugin it’s returning an error

“FPDF error: Some data has already been output, can’t send PDF file (output started at D:xampphtdocswordpresswp-includesclass.wp-styles.php:225”

I tried to solve it in a few ways. But no luck.

I am using the latest version of FPDF and WordPress. Here my code. Thanks in advance. Any solution will highly appreciated.


/*  Download pdf */

function jacgp_card() { 
    if( isset($_POST['download']) ){

        //call the FPDF library

        //A4 width : 219mm
        //default margin : 10mm each side
        //writable horizontal : 219-(10*2)=189mm

        //create pdf object
        $pdf = new FPDF('P','mm','A4');
        //add new page

        // Header
        //set font to arial, bold, 14pt
        //$pdf->Cell(45, 40, $pdf->Image('bg.jpg', $pdf->GetX(), $pdf->GetY(), 35.50), 1, 0, 'L', false );
        $pdf->Cell(189 ,20,' I am in FPDF',1,1,'C');//end of line

        //output the result

    /* Shortcode start */

 <form id="admitDform" method="POST" action="">
    <legend>Download Card</legend>
        <div class="row">
            <div class="col-md-12">
                <input type="submit" value="Download" name="download" class="download" id="download">
    $jacgp_sr_v = ob_get_clean();
    return $jacgp_sr_v;

0 2 months 0 Answers 7 views 0

Leave an answer