0

I am creating pdf using tcpdf (php,mysql) library. I want to show data as it is in database, in the pdf. Means i want to show line breaks and line spacing.

Example : Say Project subtitle in database is like this.

    The Philadelphia Foot Patrol Experiment, a randomized control trial 
    conducted by Temple University, has shown that foot patrols reduce 
    crime.

    [1] With the resources to patrol 60 locations, researchers identified 
    the highest violent crime corners in the city, using data from 2006 to 
    2008. Police commanders designed 120 foot patrol areas around these 
    corners, 

But it is outputting like this

    The Philadelphia Foot Patrol Experiment, a randomized control trial 
    conducted by Temple University, has shown that foot patrols reduce 
    crime.[1] With the resources to patrol 60 locations, researchers 
    identified the highest violent crime corners in the city, using data 
    from 2006 to 2008. Police commanders designed 120 foot patrol areas 
    around these corners, 

This is the view code in codeigniter, i have written to generate pdf

    <?php 
    $tcpdf;
    $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $obj_pdf->SetCreator(PDF_CREATOR);
    $obj_pdf->SetAuthor('Finvensys Technologies Pvt. Ltd.');
    $obj_pdf->SetTitle('Proposal Writing');
    $obj_pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, @$table->projectTitle);
    $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN,'', 14));
    $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '',9));
    $obj_pdf->SetDefaultMonospacedFont('helvetica');
    $obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $obj_pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $obj_pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $obj_pdf->SetFont('helvetica', '', 12);
    $obj_pdf->setFontSubsetting(false);
    $obj_pdf->AddPage();
    ob_start(); ?>

                <table border="1px" align="left" style="width=100%">
                <tr >
                     <td style="width:25%"><b>Project subtitle</b></td>  
                     <td style="width:75%"><?php echo @$table->projectSubTitle; ?></td>
                </tr>
                </table>

    <?php $title=@$table->projectTitle; ?>
    <?php
    $content = ob_get_contents();
    ob_end_clean();
    $obj_pdf->writeHTML($content, true, false, true, false, '');
    $obj_pdf->Output($title.'.pdf', 'I');
    ?> 
Mahantesh
  • 347
  • 5
  • 20

1 Answers1

0

It depends on which function you are using, but most likely you need to use <br> instead of \n (standard LF character as typically stored in database text fields). See 861809 for more detail, but just replace \n (or \r\n if your text has CR as well) with <br> and tcpdf should render the basic HTML tags for you correctly.

  • @ manassehkatz I have updated my question with code please go through that. Thanks.. – Mahantesh Jun 15 '17 at 04:50
  • @Mahantesh Where do projectTitle and projectSubtitle come from? Also, why all the ob_() stuff? Why not simply assign everything to a big string and pass that to writeHTML? – manassehkatz-Moving 2 Codidact Jun 15 '17 at 13:54
  • @ manassehkatz 1)projectTitle and projectSubtitle are fetching from the database. I shown simply two columns but i am generating pdf of a project proposal which has huge data means many columns not one or two. – Mahantesh Jun 15 '17 at 15:09