/** * Test set/get default font size */ public function testSetGetDefaultFontSize() { $phpWord = new PhpWord(); $fontSize = 16; $this->assertEquals(PhpWord::DEFAULT_FONT_SIZE, $phpWord->getDefaultFontSize()); $phpWord->setDefaultFontSize($fontSize); $this->assertEquals($fontSize, $phpWord->getDefaultFontSize()); }
public function export($path) { $phpWord = new PhpWord(); $phpWord->setDefaultFontName('Times New Roman'); $phpWord->setDefaultFontSize(12); $phpWord->addTitleStyle(1, ['size' => 26, 'bold' => true], []); $phpWord->addTitleStyle(2, ['size' => 22, 'bold' => true], []); $phpWord->addTitleStyle(3, ['size' => 18, 'bold' => true], []); $phpWord->addTitleStyle(4, ['size' => 16, 'bold' => true], []); $phpWord->addFontStyle('f_timeAndPlace', ['size' => 16, 'bold' => false]); $phpWord->addFontStyle('f_bold', ['bold' => true]); $phpWord->addFontStyle('f_italic', ['italic' => true]); $phpWord->addFontStyle('f_label', []); $phpWord->addFontStyle('f_chairName', []); $phpWord->addFontStyle('f_chairOrganisation', []); $phpWord->addFontStyle('f_presentationAuthor', ['bold' => true]); $phpWord->addFontStyle('f_presentationOrganisation', []); $phpWord->addFontStyle('f_presentationName', ['italic' => true]); $phpWord->addFontStyle('f_contributionPaperLabel', []); $phpWord->addParagraphStyle('p_contributionPaperLabel', ['lineHeight' => 1]); $phpWord->addParagraphStyle('p_presentation', ['lineHeight' => 1]); $phpWord->addParagraphStyle('p_presentationContributionPaper', ['lineHeight' => 1, 'basedOn' => 'presentation']); $phpWord->addParagraphStyle('p_chairs', []); $phpWord->addParagraphStyle('p_timeAndPlace', []); $section = $phpWord->addSection(); $section->addTitle($this->text('Research Network / Research Stream Sessions')); foreach ($this->getTypes() as $type) { if (!$this->isExportType($type)) { continue; } $section->addTitle($this->text(sprintf('%s - %s', $type, static::$typeNames[$type])), 2); foreach ($this->getSessions($type) as $session) { $start = new \DateTime($session['start']); $end = new \DateTime($session['end']); $timeAndPlace = sprintf('%s - %s / %s / %s', $start->format('H:i'), $end->format('H:i'), $start->format('jS l'), $session['room']); $section->addText($timeAndPlace, 'f_timeAndPlace', 'p_timeAndPlace'); $section->addTitle($this->text(sprintf('%s / %s', $session['short'], $session['title'])), 3); $chairs = $this->getChairs($session); if ($chairs) { $textRun = $section->addTextRun('p_chairs'); $text = count($chairs) == 1 ? 'Chair: ' : 'Chairs: '; $textRun->addText($this->text($text), 'f_label', null); foreach ($chairs as $chair) { $textRun->addText($this->text(sprintf('%s ', $chair['name'])), 'f_chairName', null); $textRun->addText($this->text(sprintf('(%s)', $chair['organisation'])), 'f_chairOrganisation', null); } } $presentations = $this->getPresentations($session['id']); $contributingPapers = array_filter($presentations, function ($p) { return $p['acceptance'] === 'Contributing Paper'; }); $otherPresentations = array_filter($presentations, function ($p) { return $p['acceptance'] !== 'Contributing Paper'; }); foreach ($otherPresentations as $presentation) { $textRun = $section->addTextRun('p_presentation'); foreach ($this->getAuthors($presentation) as $author) { $textRun->addText($this->text(sprintf('%s ', $author['name'])), 'f_presentationAuthor'); $textRun->addText($this->text(sprintf('(%s)', $author['organisation'])), 'f_presentationOrganisation'); $textRun->addText(', '); } $textRun->addText($this->text($presentation['title']), 'f_presentationName'); } if ($contributingPapers) { $section->addText('Contributed papers', 'f_contributionPaperLabel', 'p_contributionPaperLabel'); foreach ($contributingPapers as $presentation) { $textRun = $section->addTextRun('p_presentationContributionPaper'); foreach ($this->getAuthors($presentation) as $author) { $textRun->addText($this->text(sprintf('%s ', $author['name'])), 'f_presentationAuthor'); $textRun->addText($this->text(sprintf('(%s)', $author['organisation'])), 'f_presentationOrganisation'); $textRun->addText(', '); } $textRun->addText($this->text($presentation['title']), 'f_presentationName'); } } } $section->addPageBreak(); } $phpWord->save($path); }