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

Question

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.

<?php

/*  Download pdf */

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

        //call the FPDF library
        require('fpdf.php');

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


        // Header
        //set font to arial, bold, 14pt
        $pdf->SetFont('Arial','',12);
        //$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
        $pdf->Output();
    }


    /* Shortcode start */
    ob_start();
?>

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

add_shortcode('jacgp_acs','jacgp_card');
0
S.k.joy 2 months 0 Answers 7 views 0

Leave an answer