create
[ class tree: create ] [ index: create ] [ all elements ]

example

  1. <?php
  2.  
  3. /**
  4.  * Inserts a paragraph with complex formatting, floating images, links, bookmarks, footnotes/endnotes.
  5.  *
  6.  * @category   Phpdocx
  7.  * @package    examples
  8.  * @subpackage intermediate
  9.  * @copyright  Copyright (c) 2009-2013 Narcea Producciones Multimedia S.L.
  10.  *              (http://www.2mdc.com)
  11.  * @license    http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
  12.  * @version    2012.12.26
  13.  * @link       http://www.phpdocx.com
  14.  * @since      File available since Release 2.6
  15.  */
  16.  
  17. require_once '../../classes/CreateDocx.inc';
  18.  
  19. $docx new CreateDocx();
  20.  
  21. $docx->addText('This is a simple paragraph.');
  22.  
  23. $options =array('jc' => 'left',
  24.                 'sz' => '11',
  25.                );
  26.  
  27. $run_1 =array('color' => 'ff0000',
  28.               'font' => 'Arial',
  29.               'i' => 'single',
  30.               'sz' => '11',
  31.               'type' => 'text',
  32.               'text' => 'This is a run of text written in Arial 11pt, red and italics to illustrate how easy is to apply formatting to a run of text. '
  33.                );
  34. $break array('type' => 'lineBreak');
  35. $run_2 =array('color' => '00ff00',
  36.               'font' => 'Arial',
  37.               'sz' => '12',
  38.               'type' => 'text',
  39.               'text' => 'This is a run of text written in Arial 12pt and green color so you may check how properties are inherited or not from the general paragraph options. '
  40.                );    
  41. $image_1 array('type' => 'image',
  42.                     'src' => '../files/img/logo_header.jpg'
  43.                     'border' => 1
  44.                     'borderColor' => '444',
  45.                     'spacingLeft' => 20
  46.                     'spacingRight' => 0
  47.                     'spacingTop' => 10
  48.                     'spacingBottom' => 10
  49.                     'position' => 'right');                          
  50. $run_3 =array('sz' => '11',
  51.               'type' => 'text',
  52.               'text' => 'This run of text is written in normal black text with the default document font (usually calibri).
  53.                          Since PHPDocX v2.6 we may insert in a simple manner paragraphs that include complex formatting,
  54.                          floating images, links, bookmarks and even footnotes and endnotes in a very simple manner. '
  55.                )
  56. $run_4 =array('type' => 'text',
  57.               'text' => 'To include a footnote'
  58.                )
  59. $footnote_1 array('type' => 'footnote',
  60.                     'sz' => '10',
  61.                     'color' => '555',
  62.                     'text' => 'You can even style the footnotes content, please, look in the documentation.'      
  63.                                         );         
  64. $run_5 =array('type' => 'text',
  65.               'text' => 'in the middle of the paragraph is as simple as this.'
  66.                );              
  67. $link_1 =array('type' => 'link',
  68.                'URL' => 'http://www.phpdocx.com',
  69.                'text' => ' We also include this link'
  70.                );
  71. $bookmark_1 array('type' => 'link',
  72.                     'markerName' => 'personal',
  73.                     'sz' => '11',
  74.                     'text' => '. And we finish this paragraph bookmarking this run of text.'      
  75.                                         );                
  76.                
  77. $parameters array($run_1$break$run_2$image_1$run_3$run_4$footnote_1$run_5$link_1$bookmark_1);
  78.  
  79. $docx->addParagraph($parameters$options);
  80.  
  81. $run_1=array('type' => 'text',
  82.               'text' => 'We may now link internally to the bookmark we have included '
  83.                );              
  84. $link_1 =array('type' => 'link',
  85.                'URL' => '#personal',
  86.                'text' => 'here'
  87.                );
  88. $run_3=array('type' => 'text',
  89.               'text' => ' just by including a URL parameter as it is done usually with anchors.'
  90.                );
  91.                
  92. $parameters2 array($run_1$link_1$run_3);     
  93. $docx->addParagraph($parameters2$options);
  94.          
  95.  
  96.  
  97. $docx->addText('We are now going to insert the first complex paragraph in a table cell:');
  98.  
  99. $options =array('jc' => 'left',
  100.                 'sz' => '11',
  101.                 'rawWordML' => true
  102.                );
  103. $Pdata $docx->addParagraph($parameters$options);
  104.  
  105. $fragment $docx->createWordMLFragment($Pdata);
  106.  
  107. $valuesTable array(
  108.     array(
  109.         11,
  110.         12
  111.     ),
  112.     array(
  113.         $fragment,
  114.         22
  115.     ),
  116. );
  117.  
  118. $paramsTable array(
  119.     'border' => 'single',
  120.     'border_sz' => 5,
  121. );
  122.  
  123. $test $docx->addTable($valuesTable$paramsTable);
  124.  
  125. $docx->createDocx('../docx/example_complex_paragraph');

Documentation generated on Mon, 13 Jan 2014 13:44:09 +0100 by phpDocumentor 1.4.4