Skip to content

undesired pagebreaks in a foreach loop #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alainjouve opened this issue Jan 22, 2021 · 1 comment
Open

undesired pagebreaks in a foreach loop #2007

alainjouve opened this issue Jan 22, 2021 · 1 comment

Comments

@alainjouve
Copy link

Describe the Bug

An undesired pagebreak in a odt document appears before each $section->add($texte, $font).
These instructions are in a foreach loop. Here is the code :

Steps to Reproduce

     $phpWord = new  \PhpOffice\PhpWord\PhpWord();
    $section = $phpWord->addSection();
    $fontTitre = 'styletitre';
            $phpWord->addFontStyle(
                $fontTitre,
                array('name' => 'Tahoma', 'size' => 13 , 'color' => '0000FF', 'bold' => true)
            );
   $fontTexte = 'styletexte';
            $phpWord->addFontStyle(
                $fontTexte,
                array('name' => 'Arial', 'size' => 13, 'color' => '000000')
  if ($form->get('eleves')->isClicked()){
        $livredor=$this->getDoctrine()
                            ->getManager()
                            ->getRepository('App:Livredoreleves')->findAll();
 foreach($livredor as $texte){ 
        $equipe= $texte->getEquipe();
        $titre='Equipe '.$texte->getEquipe()->getInfoequipenat().' ('.$texte->getNoms().')';
        $section->addText($titre, $fontTitre);  
        $section->addTextBreak();
        $section->addText($texte->getTexte(),$fontTexte);  
        $lineStyle = array('weight' => 1, 'width' => 200, 'height' => 0, 'color'=> '000000');
        $section->addTextBreak(3);
         }
    $fileName='Livre_d_or_eleves.odt';
 }
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    header('Content-Type: application/vnd.oasis.opendocument.text');
    header('Cache-Control: max-age=0');
   $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord,'ODText');
   $objWriter ->save('php://output');

Expected Behavior

Pagebreaks should not appear. Each $section->addText(... should write a the same page

Current Behavior

Each $section->addText(... writes a text in an other page

Context

  • Symfony 5.1
  • PHP Version:7.4
  • PHPWord Version:0.16

Thanks for your answer.
AJ

@oleibman
Copy link
Contributor

I believe that PR #1796, which was merged on Dec. 29 2020, fixes this problem. You can get that code, and other useful changes, by cloning the project. It is officially target as part of PHPWord Version 0.18.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants