htmltodocxphpword

where u have html tags in return $html
3 followers
  • download the api(New Folder.zip) and extract it to your vendor folder
  • copy the below code to your controller method
  • put all files outside "new folder" but inside vendors
public function actionDownload() {
   //first unregister Yii base Autoload    
   spl_autoload_unregister(array('YiiBase','autoload'));
   Yii::import('application.vendors.*');
   Yii::setPathOfAlias('phpword',Yii::getPathOfAlias('application.vendors.phpword'));
 
   require('PHPWord/PHPWord.php');
   require_once 'phpword/PHPWord.php';
   require_once 'simplehtmldom/simple_html_dom.php';
   require_once 'htmltodocx_converter/h2d_htmlconverter.php';
   require_once 'example_files/styles.inc';
 
   $PHPWord = new PHPWord();
   spl_autoload_register(array('YiiBase','autoload')); 
 
   //$mCanvasType = Yii::app()->user->getState('mCanvasType'); 
   //Your Yii methods variables call here
   //or you can call your method ie.
   //$html = $this->html->data();//returned $html or your HTML/XHTML DOM.
 
   spl_autoload_unregister(array('YiiBase','autoload'));
 
   $phpword_object = new PHPWord();
   $section = $phpword_object->createSection();
   $html_dom = new simple_html_dom();
   $html_dom->load('html body' . $html . 'body html'); // here $html is the Html/XHTML DOM Which You Have to pass
   $html_dom_array = $html_dom->find('html',0)->children();
 
   $initial_state = array(
 
      // Required parameters:
      'phpword_object' => &$phpword_object, // Must be passed by reference.
      'base_root' => 'http://test.local', // Required for link elements - change it to your domain.
      'base_path' => '/htmltodocx/', // Path from base_root to whatever url your links are relative to.
 
      // Optional parameters - showing the defaults if you don't set anything:
      'current_style' => array('size' => '11'), // The PHPWord style on the top element - may be inherited by descendent elements.
      'parents' => array(0 => 'body'), // Our parent is body.
      'list_depth' => 0, // This is the current depth of any current list.
      'context' => 'section', // Possible values - section, footer or header.
      'pseudo_list' => TRUE, // NOTE: Word lists not yet supported (TRUE is the only option at present).
      'pseudo_list_indicator_font_name' => 'Wingdings', // Bullet indicator font.
      'pseudo_list_indicator_font_size' => '7', // Bullet indicator size.
      'pseudo_list_indicator_character' => 'l ', // Gives a circle bullet point with wingdings.
      'table_allowed' => TRUE, // Note, if you are adding this html into a PHPWord table you should set this to FALSE: tables cannot be nested in PHPWord.
      'treat_div_as_paragraph' => TRUE, // If set to TRUE, each new div will trigger a new line in the Word document.
 
      // Optional - no default:    
      'style_sheet' => htmltodocx_styles_example(), // This is an array (the "style sheet") - returned by htmltodocx_styles_example() here (in styles.inc) - see this function for an example of how to construct this array.
   );  
   htmltodocx_insert_html($section, $html_dom_array[0]->nodes, $initial_state);
   $html_dom->clear(); 
   unset($html_dom);
 
   $h2d_file_uri = tempnam('', 'htd');
   $objWriter = PHPWord_IOFactory::createWriter($phpword_object, 'Word2007');
   $objWriter->save($h2d_file_uri);
 
   // Download the file:
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Disposition: attachment; filename=example.docx');
   header('Content-Transfer-Encoding: binary');
   header('Expires: 0');
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   header('Pragma: public');
   header('Content-Length: ' . filesize($h2d_file_uri));
   ob_clean();
   flush();
   $status = readfile($h2d_file_uri);
   unlink($h2d_file_uri);
   exit;
}

**Nothing else welcome in advance **

Total 1 comment

#17036 report it
ShobhitPokhriyal at 2014/04/27 12:14pm
infinite scroller custome

function getProppertyItems(searchType) { var page = 1; getPropertyPageAjax(page,searchType); $(window).scroll(function() { if ($(window).scrollTop() + $(window).height() == $(document).height()) { if(completeRequest==0){ //alert('page'+page); if(page!=1){ getPropertyPageAjax(page,searchType); } page++; } } }); }

function getPropertyPageAjax(page,searchType){ if(searchType!=2){ var data = { page: page, searchType:searchType }; }else{ var data = { page: page, searchType:searchType, location:$('#location').val(), product_cat:$('#product_cat').val(), min_price:$('#min_price').val(), max_price:$('#max_price').val() }; }

$.ajax({
    type: "POST",
    url: $('#base_url_js').val()+'index.php/client/allPropertyListing',
    data: data,
    beforeSend:function(){
        $('#more_result').css('opacity',1);
    },
    success: function(res) {
        if(res.length==0){
            completeRequest = 1;
        }
        $("#all_products_items").append(res);
    },
    complete:function(){
        $('#more_result').css('opacity',0);
    }
});

}

Leave a comment

Please to leave your comment.

Create extension
Downloads