public function updateBarcode($observer)
 {
     $model = $observer['model'];
     if ($this->_barcode_before != $model->getBarcode() || $this->_barcode_type_before != $model->getBarcodeType() || $this->_barcode_order_before != $model->getBarcodeOrder() || $this->_barcode_invoice_before != $model->getBarcodeInvoice() || $this->_barcode_creditmemo_before != $model->getBarcodeCreditmemo()) {
         //if is update
         $barcode_type = $model->getBarcodeType();
         $barcode_order = $model->getBarcodeOrder();
         $barcode_invoice = $model->getBarcodeInvoice();
         $barcode_creditmemo = $model->getBarcodeCreditmemo();
         $order_html = $model->getOrderHtml();
         $invoice_html = $model->getInvoiceHtml();
         $creditmemo_html = $model->getCreditmemoHtml();
         //define dom
         $order_html_dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
         $invoice_html_dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
         $creditmemo_html_dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
         //init dom html
         if ($order_html != '') {
             $order_html_dom->load($order_html);
         }
         if ($invoice_html != '') {
             $invoice_html_dom->load($invoice_html);
         }
         if ($creditmemo_html != '') {
             $creditmemo_html_dom->load($creditmemo_html);
         }
         if ($model->getBarcode() == '1') {
             try {
                 //update barcode for order
                 if ($order_html_dom->root->innertext) {
                     $barcodeBoxOrder = $order_html_dom->find('.barcode', 0);
                     if ($barcodeBoxOrder->find('barcode', 0)) {
                         $barTag = $barcodeBoxOrder->find('barcode', 0);
                         $barTag->code = $barcode_order;
                         $barTag->type = $barcode_type;
                     } else {
                         $barcodeBoxOrder->innertext = '<barcode code="' . $barcode_order . '" type="' . $barcode_type . '" />';
                     }
                     $model->setOrderHtml($order_html_dom->save());
                 }
                 //update barcode for invoice
                 if ($invoice_html_dom->root->innertext) {
                     $barcodeBoxInvoice = $invoice_html_dom->find('.barcode', 0);
                     if ($barcodeBoxInvoice->find('barcode', 0)) {
                         $barTag = $barcodeBoxInvoice->find('barcode', 0);
                         $barTag->code = $barcode_invoice;
                         $barTag->type = $barcode_type;
                     } else {
                         $barcodeBoxInvoice->innertext = '<barcode code="' . $barcode_invoice . '" type="' . $barcode_type . '" />';
                     }
                     $model->setInvoiceHtml($invoice_html_dom->save());
                 }
                 if ($creditmemo_html_dom->root->innertext) {
                     //update barcode for Creditmemo
                     $barcodeBoxCreditmemo = $creditmemo_html_dom->find('.barcode', 0);
                     if ($barcodeBoxCreditmemo->find('barcode', 0)) {
                         $barTag = $barcodeBoxCreditmemo->find('barcode', 0);
                         $barTag->code = $barcode_creditmemo;
                         $barTag->type = $barcode_type;
                     } else {
                         $barcodeBoxCreditmemo->innertext = '<barcode code="' . $barcode_creditmemo . '" type="' . $barcode_type . '" />';
                     }
                     $model->setCreditmemoHtml($creditmemo_html_dom->save());
                 }
                 $model->save();
             } catch (Exception $e) {
             }
         } else {
             //update barcode for order
             if ($order_html_dom->root->innertext) {
                 $order_html_dom->find('.barcode', 0)->innertext = '';
                 $model->setOrderHtml($order_html_dom->save());
             }
             //update barcode for invoice
             if ($invoice_html_dom->root->innertext) {
                 $invoice_html_dom->find('.barcode', 0)->innertext = '';
                 $model->setInvoiceHtml($invoice_html_dom->save());
             }
             //update barcode for Creditmemo
             if ($creditmemo_html_dom->root->innertext) {
                 $creditmemo_html_dom->find('.barcode', 0)->innertext = '';
                 $model->setCreditmemoHtml($creditmemo_html_dom->save());
             }
             $model->save();
         }
     }
     return $this;
 }
 public function getCss($html)
 {
     $html_dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     $html_dom->load($html);
     $style = $html_dom->find('#container-inner', 0)->style;
     $template = Mage::helper('pdfinvoiceplus/pdf')->getUsingTemplate();
     $background = $template->getBackgroundImage();
     if ($background) {
         $css = '
             body{' . $style . '}
             #container-inner{background-image:none !important;
         ';
         return $css;
     }
     return null;
 }
 /**
  * 
  * @param type $html
  * @return array("{{var name}} => array('label'=>'text','value'=>'{{var name}}')")
  */
 protected function _getTotalHtmlVars($html)
 {
     $dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     $dom->load($html);
     //get label array
     $rows_total = $dom->find(".body-total > .total-row");
     //merger key => value
     $arr_mer = array();
     foreach ($rows_total as $rowElement) {
         preg_match('/\\{\\{.*\\}\\}/', $rowElement->find('.total-value', 0)->innertext, $matched);
         $arr_mer[$matched[0]]['value'] = $matched[0];
         $arr_mer[$matched[0]]['label'] = $rowElement->find('.total-label', 0)->innertext;
     }
     return $arr_mer;
 }
 public function htmlDomAction()
 {
     $html = Mage::getModel('pdfinvoiceplus/template')->load(1);
     $dom = new SimpleHtmlDoom_SimpleHtmlDoomLoad();
     $dom->load($html->getInvoiceHtml());
     //$col = $dom->find(".col-total-label");
     $col = $dom->find(".col-total-label");
     $col = $col[0];
     //$col->appendChild($childs[3]);
     //$child[0]->appendChild($child[0]->childNodes[3]);
     //echo print_r($col->childNodes(3)->outertext);
     //echo "============";
     //echo $col->__toString();
     $child = $col->children();
     //$col->appendChild($col->childNodes(3));
     echo $child[0]->__toString();
 }