Example #1
0
 /**
  * Test various conversions
  */
 public function testConversions()
 {
     $original = 1;
     $result = Font::fontSizeToPixels($original);
     $this->assertEquals($original * 16 / 12, $result);
     $result = Font::inchSizeToPixels($original);
     $this->assertEquals($original * 96, $result);
     $result = Font::centimeterSizeToPixels($original);
     $this->assertEquals($original * 37.795275591, $result);
     $result = Font::centimeterSizeToTwips($original);
     $this->assertEquals($original * 565.217, $result);
     $result = Font::inchSizeToTwips($original);
     $this->assertEquals($original * 565.217 * 2.54, $result);
     $result = Font::pixelSizeToTwips($original);
     $this->assertEquals($original * 565.217 / 37.795275591, $result);
     $result = Font::pointSizeToTwips($original);
     $this->assertEquals($original * 20, $result);
 }
Example #2
0
 /**
  * Write element
  *
  * @return string
  */
 public function write()
 {
     if (!$this->element instanceof ImageElement) {
         return '';
     }
     $this->getStyles();
     $style = $this->element->getStyle();
     $content = '';
     $content .= $this->writeOpening();
     $content .= '{\\*\\shppict {\\pict';
     $content .= '\\pngblip\\picscalex100\\picscaley100';
     $content .= '\\picwgoal' . round(Font::pixelSizeToTwips($style->getWidth()));
     $content .= '\\pichgoal' . round(Font::pixelSizeToTwips($style->getHeight()));
     $content .= PHP_EOL;
     $content .= $this->element->getImageStringData();
     $content .= '}}';
     $content .= $this->writeClosing();
     return $content;
 }
<?php

include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array('align' => 'both', 'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(12), 'spacing' => 120));
// Sample
$section = $phpWord->addSection();
$section->addText('Below are the samples on how to control your paragraph ' . 'pagination. See "Line and Page Break" tab on paragraph properties ' . 'window to see the attribute set by these controls.', array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
$section->addText('Paragraph with widowControl = false (default: true). ' . 'A "widow" is the last line of a paragraph printed by itself at the top ' . 'of a page. An "orphan" is the first line of a paragraph printed by ' . 'itself at the bottom of a page. Set this option to "false" if you want ' . 'to disable this automatic control.', null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
$section->addText('Paragraph with keepNext = true (default: false). ' . '"Keep with next" is used to prevent Word from inserting automatic page ' . 'breaks between paragraphs. Set this option to "true" if you do not want ' . 'your paragraph to be separated with the next paragraph.', null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
$section->addText('Paragraph with keepLines = true (default: false). ' . '"Keep lines together" will prevent Word from inserting an automatic page ' . 'break within a paragraph. Set this option to "true" if you do not want ' . 'all lines of your paragraph to be in the same page.', null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
$section->addText('Keep scrolling. More below.');
$section->addText('Paragraph with pageBreakBefore = true (default: false). ' . 'Different with all other control above, "page break before" separates ' . 'your paragraph into the next page. This option is most useful for ' . 'heading styles.', null, array('pageBreakBefore' => true));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}