Example #1
0
 /**
  * Test: tokenize
  *
  * @param string $html           html to test
  * @param array  $expectedTokens expected token
  *
  * @dataProvider tokenizeProvider
  */
 public function testTokenize($html, $expectedTokens)
 {
     $lexer = new HtmlLexer();
     $tokens = $lexer->tokenize($html);
     $this->assertEquals(count($expectedTokens), count($tokens));
     for ($i = 0; $i < count($tokens); $i++) {
         $this->assertEquals($expectedTokens[$i][0], $tokens[$i]->getType());
         $this->assertEquals($expectedTokens[$i][1], $tokens[$i]->getData());
         $this->assertEquals($expectedTokens[$i][2], $tokens[$i]->getLine());
     }
 }
Example #2
0
 /**
  * convert HTML to PDF
  *
  * @param string $html
  *
  * @return Html2Pdf
  */
 public function writeHTML($html)
 {
     $html = $this->parsingHtml->prepareHtml($html);
     $html = $this->parsingCss->extractStyle($html);
     $this->parsingHtml->parse($this->lexer->tokenize($html));
     $this->_makeHTMLcode();
     return $this;
 }
Example #3
0
 /**
  * convert HTML to PDF
  *
  * @access public
  * @param  string   $html
  * @param  boolean  $debugVue  enable the HTML debug vue
  * @return null
  */
 public function writeHTML($html, $debugVue = false)
 {
     // if it is a real html page, we have to convert it
     if (preg_match('/<body/isU', $html)) {
         $html = $this->getHtmlFromPage($html);
     }
     $html = str_replace('[[date_y]]', date('Y'), $html);
     $html = str_replace('[[date_m]]', date('m'), $html);
     $html = str_replace('[[date_d]]', date('d'), $html);
     $html = str_replace('[[date_h]]', date('H'), $html);
     $html = str_replace('[[date_i]]', date('i'), $html);
     $html = str_replace('[[date_s]]', date('s'), $html);
     // If we are in HTML debug vue : display the HTML
     if ($debugVue) {
         return $this->_vueHTML($html);
     }
     // convert HTMl to PDF
     $this->parsingCss->readStyle($html);
     $this->parsingHtml->parse($this->lexer->tokenize($html));
     $this->_makeHTMLcode();
 }