mpdf = $mpdf; $this->tablecascadeCSS = array(); $this->CSS=array(); $this->cascadeCSS = array(); $this->tbCSSlvl = 0; } function ReadCSS($html) { preg_match_all('/]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m); for($i=0; $impdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) { $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html); } } preg_match_all('/]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m); for($i=0; $impdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) { $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html); } } // mPDF 5.5.02 // Remove Comment tags inside CSS as ', $html); preg_match_all('/(.*?)<\/style>/si',$html,$m); if (count($m[1])) { for($i=0;$i)/s',' ',$m[1][$i]); $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).''; $html = str_replace('>'.$m[1][$i].'', $sub, $html); } } $html = preg_replace('//i','',$html); $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html); $match = 0; // no match for instance $regexp = ''; // This helps debugging: showing what is the REAL string being processed $CSSext = array(); //CSS inside external files $regexp = '/]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = $cxt[1]; } $regexp = '/]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } // look for @import stylesheets //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si'; $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } // look for @import without the url() //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si'; $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si'; $x = preg_match_all($regexp,$html,$cxt); if ($x) { $match += $x; $CSSext = array_merge($CSSext,$cxt[1]); } $ind = 0; $CSSstr = ''; if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array(); while($match){ $path = $CSSext[$ind]; $path = htmlspecialchars_decode($path); // mPDF 6 $this->mpdf->GetFullPath($path); $CSSextblock = $this->mpdf->_get_file($path); if ($CSSextblock) { // look for embedded @import stylesheets in other stylesheets // and fix url paths (including background-images) relative to stylesheet //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si'; $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si'; $xem = preg_match_all($regexpem,$CSSextblock,$cxtem); $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/'; if ($xem) { foreach($cxtem[1] AS $cxtembedded) { // path is relative to original stlyesheet!! $this->mpdf->GetFullPath($cxtembedded, $cssBasePath ); $match++; $CSSext[] = $cxtembedded; } } $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si'; $xem = preg_match_all($regexpem,$CSSextblock,$cxtem); if ($xem) { for ($i=0;$impdf->GetFullPath($embedded, $cssBasePath ); $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock); } } } $CSSstr .= ' '.$CSSextblock; } $match--; $ind++; } //end of match $match = 0; // reset value, if needed // CSS as