FPDF How to force a page break

前端 未结 1 1536
无人共我
无人共我 2021-01-19 02:28

I am using FPDF (1.7) to convert a TXT file into PDF. I would like to force a page break in the PDF product. The text file is created using php, and successfully uses carr

相关标签:
1条回答
  • 2021-01-19 03:35

    Here's an idea: Edit: complete code

    <?php
        require('fpdf.php');
        $pdf = new FPDF('P','mm','A5');
        $pdf->AddPage('P'); 
        $pdf->SetDisplayMode(real,'default');
        $pdf->SetFont('Arial','',10);
        $txt = file_get_contents('comments.txt', true);
        $pages = explode('~', $txt);
        foreach ($pages as $page) {
            $pdf->Write(8, $page);
            $pdf->AddPage();
        }
        $pdf->Output();
    ?>
    

    Brief explanation in case not clear: Splits the text up into 'pages' and writes each of them with a page break in between.

    Possible bugs: adding extra page at the end. Solution: iterate with for loop instead of foreach and stop one page short.

    Another possible bug: won't be able to ever use tilde again. (Bad) solution: use a more complex string to signify a page break.

    0 讨论(0)
提交回复
热议问题