PHP Classes

File: examples/htmlparser_yourstyle.php

Recommend this page to a friend!
  Packages of Raskin Veniamin   VS PHP Word HTML   examples/htmlparser_yourstyle.php   Download  
File: examples/htmlparser_yourstyle.php
Role: Example script
Content type: text/plain
Description: Example script
Class: VS PHP Word HTML
Create DOCX Word document dynamically from HTML
Author: By
Last change: fix bags
Date: 11 years ago
Size: 942 bytes
 

 

Contents

Class file image Download
<?php
/**
* Example of adding their styles to the document handler.
*/

require_once '../vsword/VsWord.php'; 
VsWord::autoLoad();

class MyInitNode implements IInitNode {

    /**
    * @param string $tagName
    * @param mixed $attributes
    * @return Node
    */
    function initNode($tagName, $attributes) {   
        if($tagName == 'p' && isset($attributes['class']) && $attributes['class'] == 'BigText') {
                $p = new PCompositeNode();
                $r = new RCompositeNode();
                $p->addNode($r); 
                $r->addTextStyle(new BoldStyleNode());
                $r->addTextStyle(new FontSizeStyleNode(36));  
                return $p;
        }
        return NULL;
    }
}

$doc = new VsWord();  
$parser = new HtmlParser($doc);
$parser->addHandlerInitNode( new MyInitNode() );

$parser->parse('<p class="BigText">Image 1</p><br/><img  alt="image1" src="img1.jpg"><i>The cat =)</i>');

echo '<pre>'.($doc->getDocument()->getBody()->look()).'</pre>';

$doc->saveAs('htmlparser_yourstyle.docx');