Register Lost your password?

Blog - News

Creating a PDF document using PHPdocx

June 6th, 2011 | Comments Off

PHPdocx can create PDF documents creating first the docx and then transform it to PDF.

You only need to add the transform at the end of the document like this:


// You need to call also TransformDoc.inc to create a PDF
require_once '../../classes/TransformDoc.inc';
require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$text = '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. ' .
    'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
    'officia deserunt mollit anim id est laborum.';

$paramsText = array(
    'b' => 'single',
    'font' => 'Arial'
);

$docx->addText($text, $paramsText);
$docx->createDocx('example_mixed');

// Creating the PDF
$document = new TransformDoc();
$document->setStrFile('example_mixed.docx');
$document->generatePDF();

Adding HTML to a docx document created with PHPdocx

June 6th, 2011 | 1 Comment »

Add HTML to a docx document with PHPdocx is easy. In this example you can see how to add some HTML and the format of it.

Here is the code:


require_once('../../classes/CreateDocx.inc');

$docx = new CreateDocx();

$html = '
<span>
<h3>Dynamic DOCX generation. <span style="font-size: 17px; padding: 0pt; color: rgb(0, 0, 0); margin: 9px 0pt 0pt;"><img src="http://www.phpdocx.com/wp-content/themes/lightword/images/new.gif" style="vertical-align: middle;"> New 2.2 version<br>
  <strong style="color: rgb(4, 133, 232); font-weight: normal;">with support for OpenOffice Documents, rewritten and faster API<br>
    and  <a href="features" style="color: rgb(4, 133, 232);">new features</a>!</strong></span></h3>
<p>Do you need to dynamically generate Word documents?.</p>
<p> <strong>PHPDOCX</strong> do this and much more. You may create highly customized reports in Word extracting data directly from any database or spreadsheet. These reports may include editable graphs, images, tables, headers, footers, etcetera. <strong>PHPDOCX</strong>&nbsp; can create Word documents from scratch or use predefined templates to simplify your work. With a few lines of code you may integrate <strong>PHPDOCX</strong> in your website or intranet and offer a valuable service to your customers and employees..</p>

<div style="clear: both;"></div>

<a href="wordpress/download" class="download_home">DOWNLOAD NOW</a>
<p>Do you need this functionality with Java ?  <a href="http://www.javadocx.com" class="link_destacado">Try JavadocX!</a></p>
<div class="compatible">
<h3>100% compatibility</h3><h3>
    <img src="http://www.phpdocx.com/wp-content/themes/lightword/images/100_compatibility.gif" alt="100% compatibility"></h3></div>
</span>';

$docx->addHTML($html);

$html = '
<div class="index_caja">
<h2>What is PHPDOCX ?</h2>
<p><strong>PHPDOCX</strong> is a PHP library designed to generate completely dynamic and fully customizable Word documents. </p>
<p><strong>PHPDOCX</strong> is hosted in your server providing a very and complete flexible solution for your document and<strong> report generation needs</strong>.</p>
<h2>What can I do with PHPDOCX ?</h2>

<p>With a few lines of code you can generate a complete report that includes: </p>
<ul>
  <li> Editable Text</li>
  <li>Images and Graphic elements</li>
  <li>Standard paragraphs</li>
  <li>Bulleted or numbered lists</li>
  <li>Customized tables</li>

  <li>Dynamic tables</li>
  <li>All kind of customizable and editable charts or graphs to display numerical data</li>
  <li>Tables of content to simplify readability within long documents</li>
  <li>Headers that will reflect your corporate branding</li>
  <li>Footers with automatic page numbering </li>
  </ul>

<p>You could also create and use your own templates for Mailmerge or to generate really sophisticated reports and documents. </p>
<h2><a href="blog-news"><img src="http://www.phpdocx.com/wp-content/themes/lightword/images/index_blog.gif" alt="blog news"> Latest Blog entries</a></h2>
</div>';

$docx->addHTML($html);

$docx->createDocx('example_html');

Give style to a table in PHPdocx

June 6th, 2011 | Comments Off

You need more and more personalization to create a table in PHPdocx?.

You can check and learn some of the features you can use to obtain a customized table in your docx document:


require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$frameworks = array(
				array('name' => 'Code Igniter',
					'ajax' => 'Prototype/script.aculo.us, jQuery/jQuery UI',
					'mvc' => 'Modified active record pattern',
					'orm' => 'No',
					'security' => 'Yes'
				),
				array('name' => 'Drupal',
					'ajax' => 'jQuery/jQuery UI, more',
					'mvc' => 'No',
					'orm' => 'Optional module',
					'security' => 'Yes'
				),
				array('name' => 'eZ Components',
					'ajax' => 'No',
					'mvc' => 'Yes',
					'orm' => 'Yes',
					'security' => 'Yes'
				),
				array('name' => 'Symfony',
					'ajax' => 'Prototype, script.aculo.us, Unobtrusive Ajax ' .
							'with UJS and PJS plugins',
					'mvc' => 'Push',
					'orm' => 'Yes',
					'security' => 'Plugin'
				),
				array('name' => 'Zend Framework',
					'ajax' => 'Toolkit-independent',
					'mvc' => 'Push and Pull',
					'orm' => 'Yes',
					'security' => 'ACL-based'
				)
);

$headerStyle[0] = array(
	'b' => 'single',
	'font' => 'Arial',
);

$table[] = array(
    '',
    'Ajax',
	'MVC framework',
    'ORM',
	'Security Framework(s)'
);

foreach ($frameworks as $framework) {
	$headerStyle[0]['text'] = $framework['name'];
    $table[] = array(
        $docx->addElement('addText', $headerStyle),
        $framework['ajax'],
        $framework['mvc'],
        $framework['orm'],
        $framework['security']
    );
}

$paramsTable = array(
    'TBLLOOKval' => 'ffff01E0',
    'TBLSTYLEval' => 'Tablanormal',
    'TBLWtype' => 'center',
    'TBLWw' => '50',
    'border' => 'single',
    'border_sz' => 20,
    'border_spacing' => 0,
    'border_color' => '000000',
    'jc' => 'center',
    'size_col' => 2800
);

$docx->addTable($table, $paramsTable);

$docx->createDocx('example_table_styled');

Creating and adding info to a template table in PHPdocx

June 6th, 2011 | 2 Comments »

If you have a template with a table, you can pass parameteres and info to it.

For the code, use a template like this:

docxdocumenttetemplate_2.png

Use this code:


require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$settings = array(
    'header' => true
);

$docx->addTemplate('../files/TemplateTable.docx');

$docx->addTemplateVariable(
    array(
        array(
            'NAME' => 'Product A',
            'WEIGHT' => '10',
            'PRICE' => '5',
        ),
        array(
            'NAME' => 'Product B',
            'WEIGHT' => '20',
            'PRICE' => '30',
        ),
        array(
            'NAME' => 'Product C',
            'WEIGHT' => '25',
            'PRICE' => '7',
        ),
    ),
    'table',
    $settings
);

$docx->addTemplateVariable('TOTALWEIGHT', '55');

$docx->addTemplateVariable('TOTALPRICE', '42');

$docx->addTemplateVariable('MYNAME', 'David Hume');

$docx->createDocx('template_table');

Adding the contents of a RFT document using variables in a template

June 6th, 2011 | Comments Off

Iff you have additional content in a RTF document, you can append it using a variable that call this document and place the text inside where you define the variable.

docxdocumenttetemplate.png

This is the code:


require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addTemplate('../files/TemplateText.docx');

$docx->addTemplateVariable('WEIGHT1', '10');
$docx->addTemplateVariable('WEIGHT2', '20');
$docx->addTemplateVariable('WEIGHT3', '25');

$docx->addTemplateVariable('PRICE1', '5');
$docx->addTemplateVariable('PRICE2', '30');
$docx->addTemplateVariable('PRICE3', '7');

$docx->addTemplateVariable('TOTALWEIGHT', '55');

$docx->addTemplateVariable('TOTALPRICE', '42');

// Adding the RTF document to the template
$docx->addTemplateVariable('NAME',
                           '../files/Text.rtf',
                           'rtf');

$docx->createDocx('template_rtf_text');