/** * 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 = Converter::cmToTwip($value); $this->assertEquals($value / 2.54 * 1440, $result); $result = Converter::cmToInch($value); $this->assertEquals($value / 2.54, $result); $result = Converter::cmToPixel($value); $this->assertEquals($value / 2.54 * 96, $result); $result = Converter::cmToPoint($value); $this->assertEquals($value / 2.54 * 72, $result); $result = Converter::cmToEmu($value); $this->assertEquals(round($value / 2.54 * 96 * 9525), $result); $result = Converter::inchToTwip($value); $this->assertEquals($value * 1440, $result); $result = Converter::inchToCm($value); $this->assertEquals($value * 2.54, $result); $result = Converter::inchToPixel($value); $this->assertEquals($value * 96, $result); $result = Converter::inchToPoint($value); $this->assertEquals($value * 72, $result); $result = Converter::inchToEmu($value); $this->assertEquals(round($value * 96 * 9525), $result); $result = Converter::pixelToTwip($value); $this->assertEquals($value / 96 * 1440, $result); $result = Converter::pixelToCm($value); $this->assertEquals($value / 96 * 2.54, $result); $result = Converter::pixelToPoint($value); $this->assertEquals($value / 96 * 72, $result); $result = Converter::pixelToEMU($value); $this->assertEquals(round($value * 9525), $result); $result = Converter::pointToTwip($value); $this->assertEquals($value * 20, $result); $result = Converter::pointToPixel($value); $this->assertEquals($value / 72 * 96, $result); $result = Converter::pointToEMU($value); $this->assertEquals(round($value / 72 * 96 * 9525), $result); $result = Converter::emuToPixel($value); $this->assertEquals(round($value / 9525), $result); $result = Converter::degreeToAngle($value); $this->assertEquals((int) round($value * 60000), $result); $result = Converter::angleToDegree($value); $this->assertEquals(round($value / 60000), $result); } }
$queryEj = " select UPPER(Frase) Frase from catejercicio where Ejercicio = '" . $ano . "'"; $rsEje = $cnx->Execute($queryEj); $nRowsEj = $rsEje->_numOfRows; $dataEje = array(); if ($nRowsEj > 0) { while (!$rsEje->EOF) { array_push($dataEje, array_map('utf8_encode', $rsEje->fields)); $rsEje->movenext(); } $dataEje = end($dataEje); } 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\Converter::pointToTwip(12), 'spacing' => 15, 'name' => 'Tahoma')); // Sample $section = $phpWord->addSection(array('breakType' => 'continuous')); $section->addText(htmlspecialchars($dataEje['Frase']), array('bold' => false), array('space' => array('before' => 600, 'after' => 250), 'align' => 'center')); $section->addText(htmlspecialchars('203200-' . $dataOfi['PfjOfi'] . '-' . substr($dataOfi['CveOfi'], 2, 4) . '/' . substr($ano, 2, 2)), array('bold' => false), array('space' => array('before' => 80, 'after' => 80), 'align' => 'right')); $section->addText(htmlspecialchars('Toluca de Lerdo, México;'), array('bold' => false), array('space' => array('before' => 80, 'after' => 80), 'align' => 'right')); $section->addText(htmlspecialchars($fechaOficio), array('bold' => false), array('space' => array('before' => 80, 'after' => 80), 'align' => 'right')); $table = $section->addTable('Table'); $table->addRow(300); $table->addCell(6000, array('valign' => 'center'))->addText(htmlspecialchars('Asunto:'), array('bold' => true), array('align' => 'right')); $table->addCell(4000, array('valign' => 'center'))->addText(htmlspecialchars(nl2br($dataOfi['AsuOfi'])), array('bold' => false), array('align' => 'right')); //Acentos $tit = nl2br($dataOfi['TitOfi']); $titular = explode("<br />", $tit); foreach ($titular as $tit) { $section = $phpWord->addSection(array('colsNum' => 2, 'colsSpace' => 100, 'breakType' => 'continuous'));
<?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('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::BOTH, 'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12), 'spacing' => 120)); // Sample $section = $phpWord->addSection(); $section->addText(htmlspecialchars('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.', ENT_COMPAT, 'UTF-8'), array('bold' => true), array('space' => array('before' => 360, 'after' => 480))); $section->addText(htmlspecialchars('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.', ENT_COMPAT, 'UTF-8'), null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))); $section->addText(htmlspecialchars('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.', ENT_COMPAT, 'UTF-8'), null, array('keepNext' => true, 'indentation' => array('firstLine' => 240))); $section->addText(htmlspecialchars('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.', ENT_COMPAT, 'UTF-8'), null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))); $section->addText(htmlspecialchars('Keep scrolling. More below.', ENT_COMPAT, 'UTF-8')); $section->addText(htmlspecialchars('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.', ENT_COMPAT, 'UTF-8'), null, array('pageBreakBefore' => true)); // Save file echo write($phpWord, basename(__FILE__, '.php'), $writers); if (!CLI) { include_once 'Sample_Footer.php'; }
/** * @param $value * @param $metric * @return int */ public static function toTwip($value, $metric) { $point = CRM_Utils_PDF_Utils::convertMetric($value, $metric, 'pt'); return \PhpOffice\PhpWord\Shared\Converter::pointToTwip($point); }