コード例 #1
1
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$footnote = new WordFragment($docx, 'document');
$footnote->addFootnote(array('textDocument' => 'footnote', 'textFootnote' => 'The footnote we want to insert.'));
$text = array();
$text[] = array('text' => 'Here comes the ');
$text[] = $footnote;
$text[] = array('text' => ' and some other text.');
$docx->addText($text);
$docx->addText('Some other text.');
$docx->createDocx('example_addFootnote_1');
コード例 #2
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//Create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array('src' => '../../img/image.png', 'dpi' => 300);
$default = new WordFragment($docx, 'defaultFooter');
$default->addImage($imageOptions);
$first = new WordFragment($docx, 'firstFooter');
$first->addText('first page footer.');
$even = new WordFragment($docx, 'evenFooter');
$even->addText('even page footer.');
$docx->addFooter(array('default' => $default, 'first' => $first, 'even' => $even));
//add some text
$docx->addText('This is the first page of a document with different footers for the first and even pages.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the second page.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the third page.');
$docx->createDocx('example_addFooter_2');
コード例 #3
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//Date in the header
$options_1 = array('bold' => true, 'fontSize' => 12, 'color' => 'b70000', 'dateFormat' => 'dd/MM/yyyy H:mm:ss');
$date = new WordFragment($docx);
$date->addDateAndHour($options_1);
$docx->addHeader(array('default' => $date));
$docx->addText('Let us include now different examples of the addDateAndHour with different date formatting:');
$options_2 = array('textAlign' => 'center', 'bold' => true, 'fontSize' => 14, 'color' => '333333', 'dateFormat' => "dd' of 'MMMM' of 'yyyy' at 'H:mm");
$docx->addDateAndHour($options_2);
$options_3 = array('bold' => true, 'fontSize' => 11, 'color' => '0000FF', 'dateFormat' => "MM'-'dd'-'yy");
$docx->addDateAndHour($options_3);
$docx->createDocx('example_addDateAndHour_1');
コード例 #4
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$link = new WordFragment($docx);
$link->addLink('Google', array('url' => 'http://www.google.es'));
$runs = array();
$runs[] = array('text' => 'Now we include a link to ');
$runs[] = $link;
$runs[] = array('text' => ' in the middle of a pragraph of plain text.');
$docx->addText($runs);
$docx->createDocx('example_addLink_2');
コード例 #5
0
$docx = new CreateDocx();
$docx->addText('Quisque ullamcorper, dolor eget eleifend consequat, 
    justo nunc ultricies quam, sed ullamcorper lectus urna ac justo. 
    Phasellus sed libero ut dui hendrerit tempus. Mauris tincidunt 
    laoreet sapien, feugiat viverra justo dictum eu. Cras at eros ac 
    urna accumsan varius. Vestibulum cursus gravida sollicitudin. 
    Donec vestibulum lectus id sem malesuada volutpat. Praesent et ipsum orci. 
    Sed rutrum eros id erat fermentum in auctor velit auctor. 
    Nam bibendum rutrum augue non pellentesque. Donec in mauris dui, 
    non sagittis dui. Phasellus quam leo, ultricies sit amet cursus nec, 
    elementum at est. Proin blandit volutpat odio ac dignissim. 
    In at lacus dui, sed scelerisque ante. Aliquam tempor, 
    metus sed malesuada vehicula, neque massa malesuada dolor, 
    vel semper massa ante eu nibh.');
//create a simple Word fragment to insert into the table
$textFragment = new WordFragment($docx);
$text = array();
$text[] = array('text' => 'Fit text and ');
$text[] = array('text' => 'Word fragment', 'bold' => true);
$textFragment->addText($text);
//stablish some row properties for the first row
$trProperties = array();
$trProperties[0] = array('minHeight' => 1000, 'tableHeader' => true);
$col_1_1 = array('rowspan' => 4, 'value' => '1_1', 'backgroundColor' => 'cccccc', 'borderColor' => 'b70000', 'border' => 'single', 'borderTopColor' => '0000FF', 'borderWidth' => 16, 'cellMargin' => 200);
$col_2_2 = array('rowspan' => 2, 'colspan' => 2, 'width' => 200, 'value' => $textFragment, 'backgroundColor' => 'ffff66', 'borderColor' => 'b70000', 'border' => 'single', 'cellMargin' => 200, 'fitText' => 'on', 'vAlign' => 'bottom');
$col_2_4 = array('rowspan' => 3, 'value' => 'Some rotated text', 'backgroundColor' => 'eeeeee', 'borderColor' => 'b70000', 'border' => 'single', 'borderWidth' => 16, 'textDirection' => 'tbRl');
//set teh global table properties
$options = array('columnWidths' => array(400, 1400, 400, 400, 400), 'border' => 'single', 'borderWidth' => 4, 'borderColor' => 'cccccc', 'borderSettings' => 'inside', 'float' => array('align' => 'right', 'textMargin_top' => 300, 'textMargin_right' => 400, 'textMargin_bottom' => 300, 'textMargin_left' => 400));
$values = array(array($col_1_1, '1_2', '1_3', '1_4', '1_5'), array($col_2_2, $col_2_4, '2_5'), array('3_5'), array('4_2', '4_3', '4_5'));
$docx->addTable($values, $options, $trProperties);
$docx->addText('In pretium neque vitae sem posuere volutpat. 
コード例 #6
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$comment = new WordFragment($docx, 'document');
$comment->addComment(array('textDocument' => 'comment', 'textComment' => 'The comment we want to insert.', 'initials' => 'PT', 'author' => 'PHPDocX Team', 'date' => '10 September 2000'));
$text = array();
$text[] = array('text' => 'Here comes the ');
$text[] = $comment;
$text[] = array('text' => ' and some other text.');
$docx->addText($text);
$docx->createDocx('example_addComment_1');
コード例 #7
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$text_1 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
$text_2 = 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
$break = new WordFragment($docx);
$break->addBreak();
$runs = array();
$runs[] = array('text' => $text_1);
$runs[] = $break;
$runs[] = array('text' => $text_2);
$docx->addText($runs);
$docx->createDocx('example_addBreak_2');
コード例 #8
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$bookmarkStart = new WordFragment($docx);
$bookmarkStart->addBookmark(array('type' => 'start', 'name' => 'bookmark_name'));
$bookmarkEnd = new WordFragment($docx);
$bookmarkEnd->addBookmark(array('type' => 'end', 'name' => 'bookmark_name'));
$textRuns = array();
$textRuns[] = array('text' => 'We are only going to bookmark: ');
$textRuns[] = $bookmarkStart;
$textRuns[] = array('text' => 'this words.');
$textRuns[] = $bookmarkEnd;
$docx->addText($textRuns);
$docx->createDocx('example_addBookmark_2');
コード例 #9
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//create a simple Word fragment with formatted text to be include in the textbox
$txtboxContent = new WordFragment($docx);
$runs = array();
$runs[] = array('text' => 'This text is normal.');
$runs[] = array('text' => ' And this text is red.', 'color' => 'FF0000');
$txtboxContent->addText($runs);
$textBoxOptions = array('align' => 'right', 'paddingLeft' => 5, 'width' => 140, 'height' => 140, 'contentVerticalAlign' => 'bottom');
$txtbx = new WordFragment($docx);
$txtbx->addTextBox($txtboxContent, $textBoxOptions);
$documentText = 'Text in the main document flow. Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
$textRuns = array();
$textRuns[] = $txtbx;
$textRuns[] = array('text' => $documentText);
$docx->addText($textRuns);
$docx->createDocx('example_addTextBox_3');
コード例 #10
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//Create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array('src' => '../../img/image.png', 'dpi' => 300);
$footerImage = new WordFragment($docx, 'defaultFooter');
$footerImage->addImage($imageOptions);
$docx->addFooter(array('default' => $footerImage));
//add some text
$docx->addText('This document has a footer with just one image.');
$docx->createDocx('example_addFooter_1');
コード例 #11
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//we create a few Word fragments to insert rich content in a table
$link = new WordFragment($docx);
$options = array('url' => 'http://www.google.es');
$link->addLink('Link to Google', $options);
$image = new WordFragment($docx);
$options = array('src' => '../../img/image.png');
$image->addImage($options);
$valuesTable = array(array('Title A', 'Title B', 'Title C'), array('Line A', $link, $image));
$paramsTable = array('tableStyle' => 'LightListAccent1PHPDOCX', 'tableAlign' => 'center', 'columnWidths' => array(1000, 2500, 3000));
$docx->addTable($valuesTable, $paramsTable);
$docx->createDocx('example_addTable_2');
コード例 #12
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//include the date in the middle of a text run
$dateOptions = array('bold' => true, 'color' => 'b70000', 'dateFormat' => "dd' of 'MMMM' of 'yyyy");
$date = new WordFragment($docx);
$date->addDateAndHour($dateOptions);
$text = array();
$text[] = array('text' => 'Today is the ');
$text[] = $date;
$text[] = array('text' => ' and it is a beautiful day.');
$docx->addText($text);
$docx->createDocx('example_addDateAndHour_2');
コード例 #13
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$txtbx = new WordFragment($docx);
$text = 'Some text content for the textbox. Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
$textBoxOptions = array('align' => 'left', 'paddingLeft' => 5, 'border' => false, 'fillColor' => '#ddddff', 'width' => 200);
$txtbx->addTextBox($text, $textBoxOptions);
$documentText = 'Text in the main document flow. Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' . 'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' . 'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' . 'in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
$textRuns = array();
$textRuns[] = $txtbx;
$textRuns[] = array('text' => $documentText);
$docx->addText($textRuns);
$docx->createDocx('example_addTextBox_2');
コード例 #14
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//we prepare some formatted text for insertion in the list
$textData = new WordFragment($docx);
$text = array();
$text[] = array('text' => 'We insert some ');
$text[] = array('text' => 'bold text', 'b' => 'on');
$textData->addText($text);
//and also some simple HTML to illustrate the fexibility of the method
$htmlData = new WordFragment($docx);
$html = '<i>Some HTML code</i> with a <a href="http://www.phpdocx.com">link</a>';
$htmlData->embedHTML($html);
$itemList = array('In this example we use a custom list (val = 5) that comes bundled with the default PHPdocX template.', array($textData, 'Line B', 'Line C'), $htmlData, 'Line 3');
//we set the style type to 5: other predefined Word list style
$docx->addList($itemList, 5);
$docx->createDocx('example_addList_3');
コード例 #15
0
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array('src' => '../../img/image.png', 'dpi' => 600);
$headerImage = new WordFragment($docx, 'defaultHeader');
$headerImage->addImage($imageOptions);
//create a Word Fragment with a text
$textOptions = array('fontSize' => 13, 'b' => 'on', 'color' => '567899');
$headerText = new WordFragment($docx, 'defaultHeader');
$headerText->addText('PHPDocX Header Title', $textOptions);
//create a Word Fragment with page numbering
$pageNumberOptions = array('textAlign' => 'right', 'fontSize' => 11);
$headerPageNumber = new WordFragment($docx, 'defaultHeader');
$headerPageNumber->addPageNumber('numerical', $pageNumberOptions);
//create a Word Fragment with a table that will hold all elements
//Warning: we include an additional border none property to the table cells to improve
//PDF rendering
$valuesTable = array(array(array('value' => $headerImage, 'vAlign' => 'center'), array('value' => $headerText, 'vAlign' => 'center'), array('value' => $headerPageNumber, 'vAlign' => 'center')));
$widthTableCols = array(700, 7500, 500);
$paramsTable = array('border' => 'nil', 'columnWidths' => $widthTableCols);
$headerTable = new WordFragment($docx, 'defaultHeader');
$headerTable->addTable($valuesTable, $paramsTable);
//add some text to the body of the document
$docx->addHeader(array('default' => $headerTable));
//add some text in the first page of the document
$docx->addText('This document has a header with an image, some text and page numbering.');
//add a page break so we see the numbering at work
$docx->addBreak(array('type' => 'page'));
//add some text in the first page of the document
$docx->addText('Now some text in the second page.');
$docx->createDocx('example_addHeader_2');
コード例 #16
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocxFromTemplate('../../files/TemplateWordFragment_2.docx');
//create the Word fragment that is going to replace the variable
//like the variable to replace is in a footnote we should it as target
$wf = new WordFragment($docx, 'footnote');
//create an image fragment
$image = new WordFragment($docx, 'footnote');
//Warning: you can not poition absolutely  images in footnotes. That is a limitation of the Word interface not the standard.
$image->addImage(array('src' => '../../img/image.png', 'scaling' => 10));
//and also a link fragment
$link = new WordFragment($docx, 'footnote');
$link->addLink('link to Google', array('url' => 'http://www.google.es', 'color' => '0000FF', 'u' => 'single'));
//combine them to create a paragraph
$text = array();
$text[] = $image;
$text[] = array('text' => 'I am going to write a link: ', 'b' => 'on');
$text[] = $link;
$text[] = array('text' => ' to illustrate how to include links in a footnote. ');
$text[] = array('text' => ' As you may see it is extremely simple to do so and can be done with any other Word element.');
//insert all the content in the Word fragment we are going to use for replacement
$wf->addText($text);
//we want to preserve the reference mark so we do an inline substitution to presereve the paragraph structure.
//we also target the footnote that is where the placeholder variable is located
$docx->replaceVariableByWordFragment(array('INLINEFRAGMENT' => $wf), array('type' => 'inline', 'target' => 'footnote'));
$docx->createDocx('example_replaceVariable ByWordFragment_2');
コード例 #17
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$endnote = new WordFragment($docx, 'document');
$endnote->addEndnote(array('textDocument' => 'endnote', 'textEndnote' => 'The endnote we want to insert.'));
$text = array();
$text[] = array('text' => 'Here comes the ');
$text[] = $endnote;
$text[] = array('text' => ' and some other text.');
$docx->addText($text);
$docx->addText('Some other text.');
$docx->createDocx('example_addEndnote_1');
コード例 #18
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocxFromTemplate('../../files/TemplateWordFragment_1.docx');
//create the Word fragment that is going to replace the variable
$wf = new WordFragment($docx, 'document');
//create an image fragment
$image = new WordFragment($docx, 'document');
$image->addImage(array('src' => '../../img/image.png', 'scaling' => 50, 'float' => 'right', 'textWrap' => 1));
//and also a link fragment
$link = new WordFragment($docx, 'document');
$link->addLink('link to Google', array('url' => 'http://www.google.es', 'color' => '0000FF', 'u' => 'single'));
//and a footnote fragment
$footnote = new WordFragment($docx, 'document');
$footnote->addFootnote(array('textDocument' => 'here it is', 'textFootnote' => 'This is the footnote text.'));
//combine them to create a paragraph
$text = array();
$text[] = $image;
$text[] = array('text' => 'I am going to write a link: ', 'b' => 'on');
$text[] = $link;
$text[] = array('text' => ' to illustrate how to include links. ');
$text[] = array('text' => ' As you may see is extremely simple to do so and can be done with any other Word element. For example to include  a footnote is also as simple as this: ');
$text[] = $footnote;
$text[] = array('text' => ' , as you see there is a footnote at the bootom of the page. ', 'color' => 'B70000');
//insert all the content in the Word fragment we are going to use for replacement
$wf->addText($text);
$docx->replaceVariableByWordFragment(array('WORDFRAGMENT' => $wf), array('type' => 'block'));
$docx->createDocx('example_replaceVariable ByWordFragment_1');
コード例 #19
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//Create a Word fragment with an image to be inserted in the header of the document
$imageOptions = array('src' => '../../img/image.png', 'dpi' => 300);
$headerImage = new WordFragment($docx, 'defaultHeader');
$headerImage->addImage($imageOptions);
$docx->addHeader(array('default' => $headerImage));
//add some text
$docx->addText('This document has a header with just one image.');
$docx->createDocx('example_addHeader_1');
コード例 #20
0
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$footnote = new WordFragment($docx, 'document');
$html = new WordFragment($docx, 'footnote');
//notice the different "target"
$htmlCode = '<p>This is some HTML code with a link to <a href="http://www.2mdc.com">2mdc.com</a> and a random image: 
<img src="../../img/image.png" width="35" height="35" style="vertical-align: middle"></p>';
$html->embedHTML($htmlCode, array('downloadImages' => true));
$footnote->addFootnote(array('textDocument' => 'footnote', 'textFootnote' => $html, 'footnoteMark' => array('customMark' => '*')));
$text = array();
$text[] = array('text' => 'Here comes the ');
$text[] = $footnote;
$text[] = array('text' => ' and some other text.');
$docx->addText($text);
$docx->addText('Some other text.');
$docx->createDocx('example_Footnote_2');
コード例 #21
-1
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
$docx->addText('We write a math equation using OMML (the native Word XML standard for math equations):');
$docx->addMathEquation('<m:oMathPara>
        <m:oMath><m:r><m:t>∪±∞=~×</m:t></m:r></m:oMath>
    </m:oMathPara>', 'omml');
$text = array();
$text[] = array('text' => 'The same equation inline: ');
$math = new WordFragment($docx);
$math->addMathEquation('<m:oMathPara>
        <m:oMath><m:r><m:t>∪±∞=~×</m:t></m:r></m:oMath>
    </m:oMathPara>', 'omml');
$text[] = $math;
$docx->addText($text);
$docx->createDocx('example_addMathEq_1');
コード例 #22
-1
<?php

//path to  the CreateDocx class within your PHPDocX installation
require_once '../../../classes/CreateDocx.inc';
$docx = new CreateDocx();
//create a Word fragment to insdert in the default header
$numbering = new WordFragment($docx, 'defaultHeader');
//sert some formatting options
$options = array('textAlign' => 'right', 'bold' => true, 'sz' => 14, 'color' => 'B70000');
$numbering->addPageNumber('numerical', $options);
$docx->addHeader(array('default' => $numbering));
//Now we include a couple of pages to better illustrate the example
$docx->addText('This is the first page.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the second page.');
$docx->addBreak(array('type' => 'page'));
$docx->addText('This is the third page.');
$docx->createDocx('example_addPageNumber_1');
コード例 #23
-1
		<mo>=</mo>
		<mfenced open="[" close="]">
			<mtable>
				<mtr>
					<mtd>
						<mi>x</mi>
					</mtd> 
					<mtd>
						<mn>2</mn>
					</mtd>
				</mtr>
				<mtr>
					<mtd>
						<mn>3</mn>
					</mtd>
					<mtd>
						<mi>w</mi>
					</mtd>
				</mtr>
			</mtable>
		</mfenced>
	</mrow>
</math>';
$docx->addMathEquation($mathML, 'mathmml');
$text = array();
$text[] = array('text' => 'The same equation inline: ');
$math = new WordFragment($docx);
$math->addMathEquation($mathML, 'mathml');
$text[] = $math;
$docx->addText($text);
$docx->createDocx('example_addMathML_1');