示例#1
0
 /**
  * Test unit conversion functions with various numbers
  */
 public function testUnitConversions()
 {
     $values[] = 0;
     // zero value
     $values[] = rand(1, 100) / 100;
     // fraction number
     $values[] = rand(1, 100);
     // integer
     foreach ($values as $value) {
         $result = Drawing::pixelsToEMU($value);
         $this->assertEquals(round($value * 9525), $result);
         $result = Drawing::EMUToPixels($value);
         $this->assertEquals(round($value / 9525), $result);
         $result = Drawing::pixelsToPoints($value);
         $this->assertEquals($value * 0.6777777699999999, $result);
         $result = Drawing::pointsToPixels($value);
         $this->assertEquals($value * 1.333333333, $result);
         $result = Drawing::degreesToAngle($value);
         $this->assertEquals((int) round($value * 60000), $result);
         $result = Drawing::angleToDegrees($value);
         $this->assertEquals(round($value / 60000), $result);
         $result = Drawing::pixelsToCentimeters($value);
         $this->assertEquals($value * 0.028, $result);
         $result = Drawing::centimetersToPixels($value);
         $this->assertEquals($value / 0.028, $result);
     }
 }
示例#2
0
 /**
  * Get style array
  */
 public function testStyleArray()
 {
     $oLine = new Line(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(14), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4), 'positioning' => 'absolute', 'posHorizontalRel' => 'page', 'posVerticalRel' => 'page', 'flip' => true, 'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(5), 'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, 'weight' => 10));
     $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Line', $oLine->getStyle());
 }
示例#3
0
$table->addRow();
$table->addCell(15000)->addImage('images/welcome_word1.jpg', array('align' => 'left'));
$cell = $table->addCell(4000);
$textrun = $cell->addTextRun(array('align' => 'right'));
$textrun->addText('ALG India Law Offices', array('name' => 'Times New Roman', 'size' => 13, 'bold' => true));
$textrun->addTextBreak();
$textrun->addText('30 Siri Fort Road,', array('name' => 'Times New Roman', 'size' => 11));
$textrun->addTextBreak();
$textrun->addText('New Delhi-110049', array('name' => 'Times New Roman', 'size' => 11));
$textrun->addTextBreak();
$textrun->addText('(T) : +91.11.2625.2244', array('name' => 'Times New Roman', 'size' => 11));
$textrun->addTextBreak();
$textrun->addText('(F) : +91.11.2625.1585', array('name' => 'Times New Roman', 'size' => 11));
$textrun->addTextBreak();
$textrun->addText('(E): trademarks@algindia.com', array('name' => 'Times New Roman', 'size' => 11));
$underline = $section->addLine(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(16), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0), 'positioning' => 'absolute'));
/*$textcenter1 = $section->addTextRun(array('align' => 'center'));
$textcenter1->addText('EXAMINATION, PUBLICATION AND REGISTRATION SECTION (EPR)',array('name'=>'Times New Roman', 'size'=>12, 'align' => 'center', 'bold'=>true,'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));

$textright = $section->addTextRun(array('align' => 'right'));
$textright->addText('Date: '.$currentDate.'',array('name'=>'Times New Roman', 'size'=>12));

$textleft = $section->addTextRun(array('align' => 'left'));
$textleft->addText('To',array('name'=>'Times New Roman', 'size'=>12));
$textleft->addTextBreak();
$textleft->addText('The Registrar of Trade Marks',array('name'=>'Times New Roman', 'size'=>12));
$textleft->addTextBreak();
$textleft->addText('Trade Marks Registry',array('name'=>'Times New Roman', 'size'=>12));
$textleft->addTextBreak();
$textleft->addText($jurisdiction,array('name'=>'Times New Roman', 'size'=>12));
示例#4
0
$section->addTextBreak(2);
$section->addText('Local image with styles:');
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
$section->addTextBreak(2);
// Remote image
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
$section->addText("Remote image from: {$source}");
$section->addImage($source);
//Wrapping style
$text = str_repeat('Hello World! ', 15);
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
foreach ($wrappingStyles as $wrappingStyle) {
    $section->addTextBreak(5);
    $section->addText('Wrapping style ' . $wrappingStyle);
    $section->addImage('resources/_earth.jpg', array('positioning' => 'relative', 'marginTop' => -1, 'marginLeft' => 1, 'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
    $section->addText($text);
}
//Absolute positioning
$section->addTextBreak(3);
$section->addText('Absolute positioning: see top right corner of page');
$section->addImage('resources/_mars.jpg', array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE, 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE, 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE, 'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.5), 'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55)));
//Relative positioning
$section->addTextBreak(3);
$section->addText('Relative positioning: Horizontal position center relative to column,');
$section->addText('Vertical position top relative to line');
$section->addImage('resources/_mars.jpg', array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3), 'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE, 'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER, 'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN, 'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP, 'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}
示例#5
0
 /**
  * Get style array
  */
 public function testStyleArray()
 {
     $oTextBox = new TextBox(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4.5), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(17.5), 'positioning' => 'absolute', 'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.4), 'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(9.9), 'stroke' => 0, 'innerMargin' => 0, 'borderSize' => 1, 'borderColor' => ''));
     $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TextBox', $oTextBox->getStyle());
 }
示例#6
0
<?php

include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->addSection();
// Add Line elements
// See Element/Line.php for all options
$section->addText('Horizontal Line (Inline style):');
$section->addLine(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0), 'positioning' => 'absolute'));
$section->addText('Vertical Line (Inline style):');
$section->addLine(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1), 'positioning' => 'absolute'));
// Two text break
$section->addTextBreak(1);
$section->addText('Positioned Line (red):');
$section->addLine(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1), 'positioning' => 'absolute', 'posHorizontalRel' => 'page', 'posVerticalRel' => 'page', 'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(10), 'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(8), 'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE, 'color' => 'red'));
$section->addText('Horizontal Formatted Line');
$section->addLine(array('width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15), 'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0), 'positioning' => 'absolute', 'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK, 'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL, 'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT, 'weight' => 10));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}