first commit
This commit is contained in:
168
html2pdf_v4.03/_class/exception.class.php
Executable file
168
html2pdf_v4.03/_class/exception.class.php
Executable file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* HTML2PDF Librairy - HTML2PDF Exception
|
||||
*
|
||||
* HTML => PDF convertor
|
||||
* distributed under the LGPL License
|
||||
*
|
||||
* @author Laurent MINGUET <webmaster@html2pdf.fr>
|
||||
* @version 4.03
|
||||
*/
|
||||
|
||||
class HTML2PDF_exception extends exception
|
||||
{
|
||||
protected $_tag = null;
|
||||
protected $_html = null;
|
||||
protected $_other = null;
|
||||
protected $_image = null;
|
||||
protected $_messageHtml = '';
|
||||
|
||||
/**
|
||||
* generate a HTML2PDF exception
|
||||
*
|
||||
* @param int $err error number
|
||||
* @param mixed $other additionnal informations
|
||||
* @return string $html optionnal code HTML associated to the error
|
||||
*/
|
||||
final public function __construct($err = 0, $other = null, $html = '')
|
||||
{
|
||||
// read the error
|
||||
switch($err)
|
||||
{
|
||||
case 1: // Unsupported tag
|
||||
$msg = (HTML2PDF_locale::get('err01'));
|
||||
$msg = str_replace('[[OTHER]]', $other, $msg);
|
||||
$this->_tag = $other;
|
||||
break;
|
||||
|
||||
case 2: // too long sentence
|
||||
$msg = (HTML2PDF_locale::get('err02'));
|
||||
$msg = str_replace('[[OTHER_0]]', $other[0], $msg);
|
||||
$msg = str_replace('[[OTHER_1]]', $other[1], $msg);
|
||||
$msg = str_replace('[[OTHER_2]]', $other[2], $msg);
|
||||
break;
|
||||
|
||||
case 3: // closing tag in excess
|
||||
$msg = (HTML2PDF_locale::get('err03'));
|
||||
$msg = str_replace('[[OTHER]]', $other, $msg);
|
||||
$this->_tag = $other;
|
||||
break;
|
||||
|
||||
case 4: // tags closed in the wrong order
|
||||
$msg = (HTML2PDF_locale::get('err04'));
|
||||
$msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
|
||||
break;
|
||||
|
||||
case 5: // unclosed tag
|
||||
$msg = (HTML2PDF_locale::get('err05'));
|
||||
$msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
|
||||
break;
|
||||
|
||||
case 6: // image can not be loaded
|
||||
$msg = (HTML2PDF_locale::get('err06'));
|
||||
$msg = str_replace('[[OTHER]]', $other, $msg);
|
||||
$this->_image = $other;
|
||||
break;
|
||||
|
||||
case 7: // too big TD content
|
||||
$msg = (HTML2PDF_locale::get('err07'));
|
||||
break;
|
||||
|
||||
case 8: // SVG tag not in DRAW tag
|
||||
$msg = (HTML2PDF_locale::get('err08'));
|
||||
$msg = str_replace('[[OTHER]]', $other, $msg);
|
||||
$this->_tag = $other;
|
||||
break;
|
||||
|
||||
case 9: // deprecated
|
||||
$msg = (HTML2PDF_locale::get('err09'));
|
||||
$msg = str_replace('[[OTHER_0]]', $other[0], $msg);
|
||||
$msg = str_replace('[[OTHER_1]]', $other[1], $msg);
|
||||
$this->_tag = $other[0];
|
||||
break;
|
||||
|
||||
case 0: // specific error
|
||||
default:
|
||||
$msg = $other;
|
||||
break;
|
||||
}
|
||||
|
||||
// create the HTML message
|
||||
$this->_messageHtml = '<span style="color: #AA0000; font-weight: bold;">'.HTML2PDF_locale::get('txt01', 'error: ').$err.'</span><br>';
|
||||
$this->_messageHtml.= HTML2PDF_locale::get('txt02', 'file:').' '.$this->file.'<br>';
|
||||
$this->_messageHtml.= HTML2PDF_locale::get('txt03', 'line:').' '.$this->line.'<br>';
|
||||
$this->_messageHtml.= '<br>';
|
||||
$this->_messageHtml.= $msg;
|
||||
|
||||
// create the text message
|
||||
$msg = HTML2PDF_locale::get('txt01', 'error: ').$err.' : '.strip_tags($msg);
|
||||
|
||||
// add the optionnal html content
|
||||
if ($html) {
|
||||
$this->_messageHtml.= "<br><br>HTML : ...".trim(htmlentities($html)).'...';
|
||||
$this->_html = $html;
|
||||
$msg.= ' HTML : ...'.trim($html).'...';
|
||||
}
|
||||
|
||||
// save the other informations
|
||||
$this->_other = $other;
|
||||
|
||||
// construct the exception
|
||||
parent::__construct($msg, $err);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the message as string
|
||||
*
|
||||
* @access public
|
||||
* @return string $messageHtml
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_messageHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the html tag name
|
||||
*
|
||||
* @access public
|
||||
* @return string $tagName
|
||||
*/
|
||||
public function getTAG()
|
||||
{
|
||||
return $this->_tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the optional html code
|
||||
*
|
||||
* @access public
|
||||
* @return string $html
|
||||
*/
|
||||
public function getHTML()
|
||||
{
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the optional other informations
|
||||
*
|
||||
* @access public
|
||||
* @return mixed $other
|
||||
*/
|
||||
public function getOTHER()
|
||||
{
|
||||
return $this->_other;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the image source
|
||||
*
|
||||
* @access public
|
||||
* @return string $imageSrc
|
||||
*/
|
||||
public function getIMAGE()
|
||||
{
|
||||
return $this->_image;
|
||||
}
|
||||
}
|
96
html2pdf_v4.03/_class/locale.class.php
Executable file
96
html2pdf_v4.03/_class/locale.class.php
Executable file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* HTML2PDF Librairy - HTML2PDF Locale
|
||||
*
|
||||
* HTML => PDF convertor
|
||||
* distributed under the LGPL License
|
||||
*
|
||||
* @author Laurent MINGUET <webmaster@html2pdf.fr>
|
||||
* @version 4.03
|
||||
*/
|
||||
|
||||
class HTML2PDF_locale
|
||||
{
|
||||
/**
|
||||
* code of the current used locale
|
||||
* @var string
|
||||
*/
|
||||
static protected $_code = null;
|
||||
|
||||
/**
|
||||
* texts of the current used locale
|
||||
* @var array
|
||||
*/
|
||||
static protected $_list = array();
|
||||
|
||||
/**
|
||||
* directory where locale files are
|
||||
* @var string
|
||||
*/
|
||||
static protected $_directory = null;
|
||||
|
||||
/**
|
||||
* load the locale
|
||||
*
|
||||
* @access public
|
||||
* @param string $code
|
||||
*/
|
||||
static public function load($code)
|
||||
{
|
||||
if (self::$_directory===null) {
|
||||
self::$_directory = dirname(dirname(__FILE__)).'/locale/';
|
||||
}
|
||||
|
||||
// must be in lower case
|
||||
$code = strtolower($code);
|
||||
|
||||
// must be [a-z-0-9]
|
||||
if (!preg_match('/^([a-z0-9]+)$/isU', $code)) {
|
||||
throw new HTML2PDF_exception(0, 'invalid language code ['.self::$_code.']');
|
||||
}
|
||||
|
||||
// save the code
|
||||
self::$_code = $code;
|
||||
|
||||
// get the name of the locale file
|
||||
$file = self::$_directory.self::$_code.'.csv';
|
||||
|
||||
// the file must exist
|
||||
if (!is_file($file)) {
|
||||
throw new HTML2PDF_exception(0, 'language code ['.self::$_code.'] unknown. You can create the translation file ['.$file.'] and send it to the webmaster of html2pdf in order to integrate it into a future release');
|
||||
}
|
||||
|
||||
// load the file
|
||||
self::$_list = array();
|
||||
$handle = fopen($file, 'r');
|
||||
while (!feof($handle)) {
|
||||
$line = fgetcsv($handle);
|
||||
if (count($line)!=2) continue;
|
||||
self::$_list[trim($line[0])] = trim($line[1]);
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* clean the locale
|
||||
*
|
||||
* @access public static
|
||||
*/
|
||||
static public function clean()
|
||||
{
|
||||
self::$_code = null;
|
||||
self::$_list = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* get a text
|
||||
*
|
||||
* @access public static
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
static public function get($key, $default='######')
|
||||
{
|
||||
return (isset(self::$_list[$key]) ? self::$_list[$key] : $default);
|
||||
}
|
||||
}
|
1415
html2pdf_v4.03/_class/myPdf.class.php
Executable file
1415
html2pdf_v4.03/_class/myPdf.class.php
Executable file
File diff suppressed because it is too large
Load Diff
1812
html2pdf_v4.03/_class/parsingCss.class.php
Executable file
1812
html2pdf_v4.03/_class/parsingCss.class.php
Executable file
File diff suppressed because it is too large
Load Diff
520
html2pdf_v4.03/_class/parsingHtml.class.php
Executable file
520
html2pdf_v4.03/_class/parsingHtml.class.php
Executable file
@ -0,0 +1,520 @@
|
||||
<?php
|
||||
/**
|
||||
* HTML2PDF Librairy - parsingHtml class
|
||||
*
|
||||
* HTML => PDF convertor
|
||||
* distributed under the LGPL License
|
||||
*
|
||||
* @author Laurent MINGUET <webmaster@html2pdf.fr>
|
||||
* @version 4.03
|
||||
*/
|
||||
|
||||
class HTML2PDF_parsingHtml
|
||||
{
|
||||
protected $_html = ''; // HTML code to parse
|
||||
protected $_num = 0; // table number
|
||||
protected $_level = 0; // table level
|
||||
protected $_encoding = ''; // encoding
|
||||
public $code = array(); // parsed HTML codfe
|
||||
|
||||
const HTML_TAB = ' ';
|
||||
|
||||
/**
|
||||
* main constructor
|
||||
*
|
||||
* @param string encoding
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($encoding = 'UTF-8')
|
||||
{
|
||||
$this->_num = 0;
|
||||
$this->_level = array($this->_num);
|
||||
$this->_html = '';
|
||||
$this->code = array();
|
||||
$this->setEncoding($encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* change the encoding
|
||||
*
|
||||
* @param string encoding
|
||||
* @access public
|
||||
*/
|
||||
public function setEncoding($encoding)
|
||||
{
|
||||
$this->_encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the HTML code to parse
|
||||
*
|
||||
* @param string HTML code
|
||||
* @access public
|
||||
*/
|
||||
public function setHTML($html)
|
||||
{
|
||||
// remove the HTML in comment
|
||||
$html = preg_replace('/<!--(.*)-->/isU', '', $html);
|
||||
|
||||
// save the HTML code
|
||||
$this->_html = $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the HTML code
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
$parents = array();
|
||||
|
||||
// flag : are we in a <pre> Tag ?
|
||||
$tagPreIn = false;
|
||||
|
||||
// action to use for each line of the content of a <pre> Tag
|
||||
$tagPreBr = array(
|
||||
'name' => 'br',
|
||||
'close' => false,
|
||||
'param' => array(
|
||||
'style' => array(),
|
||||
'num' => 0
|
||||
)
|
||||
);
|
||||
|
||||
// tag that can be not closed
|
||||
$tagsNotClosed = array(
|
||||
'br', 'hr', 'img', 'col',
|
||||
'input', 'link', 'option',
|
||||
'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline'
|
||||
);
|
||||
|
||||
// search the HTML tags
|
||||
$tmp = array();
|
||||
$this->_searchCode($tmp);
|
||||
|
||||
// all the actions to do
|
||||
$actions = array();
|
||||
|
||||
// foreach part of the HTML code
|
||||
foreach ($tmp as $part) {
|
||||
// if it is a tag code
|
||||
if ($part[0]=='code') {
|
||||
// analise the HTML code
|
||||
$res = $this->_analiseCode($part[1]);
|
||||
|
||||
// if it is a real HTML tag
|
||||
if ($res) {
|
||||
// save the current posistion in the HTML code
|
||||
$res['html_pos'] = $part[2];
|
||||
|
||||
// if the tag must be closed
|
||||
if (!in_array($res['name'], $tagsNotClosed)) {
|
||||
// if it is a closure tag
|
||||
if ($res['close']) {
|
||||
// HTML validation
|
||||
if (count($parents)<1)
|
||||
throw new HTML2PDF_exception(3, $res['name'], $this->getHtmlErrorCode($res['html_pos']));
|
||||
else if ($parents[count($parents)-1]!=$res['name'])
|
||||
throw new HTML2PDF_exception(4, $parents, $this->getHtmlErrorCode($res['html_pos']));
|
||||
else
|
||||
unset($parents[count($parents)-1]);
|
||||
} else {
|
||||
// if it is a autoclosed tag
|
||||
if ($res['autoclose']) {
|
||||
// save the opened tag
|
||||
$actions[] = $res;
|
||||
|
||||
// prepare the closed tag
|
||||
$res['params'] = array();
|
||||
$res['close'] = true;
|
||||
}
|
||||
// else :add a child for validation
|
||||
else
|
||||
$parents[count($parents)] = $res['name'];
|
||||
}
|
||||
|
||||
// if it is a <pre> tag (or <code> tag) not auclosed => update the flag
|
||||
if (($res['name']=='pre' || $res['name']=='code') && !$res['autoclose']) {
|
||||
$tagPreIn = !$res['close'];
|
||||
}
|
||||
}
|
||||
|
||||
// save the actions to convert
|
||||
$actions[] = $res;
|
||||
} else { // else (it is not a real HTML tag => we transform it in Texte
|
||||
$part[0]='txt';
|
||||
}
|
||||
}
|
||||
// if it is text
|
||||
if ($part[0]=='txt') {
|
||||
// if we are not in a <pre> tag
|
||||
if (!$tagPreIn) {
|
||||
// save the action
|
||||
$actions[] = array(
|
||||
'name' => 'write',
|
||||
'close' => false,
|
||||
'param' => array('txt' => $this->_prepareTxt($part[1])),
|
||||
);
|
||||
} else { // else (if we are in a <pre> tag)
|
||||
// prepare the text
|
||||
$part[1] = str_replace("\r", '', $part[1]);
|
||||
$part[1] = explode("\n", $part[1]);
|
||||
|
||||
// foreach line of the text
|
||||
foreach ($part[1] as $k => $txt) {
|
||||
// transform the line
|
||||
$txt = str_replace("\t", self::HTML_TAB, $txt);
|
||||
$txt = str_replace(' ', ' ', $txt);
|
||||
|
||||
// add a break line
|
||||
if ($k>0) $actions[] = $tagPreBr;
|
||||
|
||||
// save the action
|
||||
$actions[] = array(
|
||||
'name' => 'write',
|
||||
'close' => false,
|
||||
'param' => array('txt' => $this->_prepareTxt($txt, false)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for each indentified action, we have to clean up the begin and the end of the texte
|
||||
// based on tags that surround it
|
||||
|
||||
// list of the tags to clean
|
||||
$tagsToClean = array(
|
||||
'page', 'page_header', 'page_footer', 'form',
|
||||
'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br',
|
||||
'div', 'hr', 'p', 'ul', 'ol', 'li',
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
||||
'bookmark', 'fieldset', 'legend',
|
||||
'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline',
|
||||
'option'
|
||||
);
|
||||
|
||||
// foreach action
|
||||
$nb = count($actions);
|
||||
for ($k=0; $k<$nb; $k++) {
|
||||
// if it is a Text
|
||||
if ($actions[$k]['name']=='write') {
|
||||
// if the tag before the text is a tag to clean => ltrim on the text
|
||||
if ($k>0 && in_array($actions[$k-1]['name'], $tagsToClean))
|
||||
$actions[$k]['param']['txt'] = ltrim($actions[$k]['param']['txt']);
|
||||
|
||||
// if the tag after the text is a tag to clean => rtrim on the text
|
||||
if ($k<$nb-1 && in_array($actions[$k+1]['name'], $tagsToClean))
|
||||
$actions[$k]['param']['txt'] = rtrim($actions[$k]['param']['txt']);
|
||||
|
||||
// if the text is empty => remove the action
|
||||
if (!strlen($actions[$k]['param']['txt']))
|
||||
unset($actions[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
// if we are not on the level 0 => HTML validator ERROR
|
||||
if (count($parents)) throw new HTML2PDF_exception(5, $parents);
|
||||
|
||||
// save the actions to do
|
||||
$this->code = array_values($actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare the text
|
||||
*
|
||||
* @param string texte
|
||||
* @param boolean true => replace multiple space+\t+\r+\n by a single space
|
||||
* @return string texte
|
||||
* @access protected
|
||||
*/
|
||||
protected function _prepareTxt($txt, $spaces = true)
|
||||
{
|
||||
if ($spaces) $txt = preg_replace('/\s+/is', ' ', $txt);
|
||||
$txt = str_replace('€', '€', $txt);
|
||||
$txt = html_entity_decode($txt, ENT_QUOTES, $this->_encoding);
|
||||
return $txt;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the HTML code
|
||||
*
|
||||
* @param &array array's result
|
||||
* @return null
|
||||
*/
|
||||
protected function _searchCode(&$tmp)
|
||||
{
|
||||
// initialise the array
|
||||
$tmp = array();
|
||||
|
||||
// regexp to separate the tags from the texts
|
||||
$reg = '/(<[^>]+>)|([^<]+)+/isU';
|
||||
|
||||
// last match found
|
||||
$str = '';
|
||||
$offset = 0;
|
||||
|
||||
// As it finds a match
|
||||
while (preg_match($reg, $this->_html, $parse, PREG_OFFSET_CAPTURE, $offset)) {
|
||||
// if it is a tag
|
||||
if ($parse[1][0]) {
|
||||
// save the previous text if it exists
|
||||
if ($str!=='') $tmp[] = array('txt', $str);
|
||||
|
||||
// save the tag, with the offset
|
||||
$tmp[] = array('code', trim($parse[1][0]), $offset);
|
||||
|
||||
// init the current text
|
||||
$str = '';
|
||||
} else { // else (if it is a text)
|
||||
// add the new text to the current text
|
||||
$str.= $parse[2][0];
|
||||
}
|
||||
|
||||
// Update offset to the end of the match
|
||||
$offset = $parse[0][1] + strlen($parse[0][0]);
|
||||
unset($parse);
|
||||
}
|
||||
// if a text is present in the end, we save it
|
||||
if ($str!='') $tmp[] = array('txt', $str);
|
||||
unset($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* analise a HTML tag
|
||||
*
|
||||
* @param string HTML code to analise
|
||||
* @return array corresponding action
|
||||
*/
|
||||
protected function _analiseCode($code)
|
||||
{
|
||||
// name of the tag, opening, closure, autoclosure
|
||||
$tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)';
|
||||
if (!preg_match('/'.$tag.'/isU', $code, $match)) return null;
|
||||
$close = ($match[1]=='/' ? true : false);
|
||||
$autoclose = preg_match('/\/>$/isU', $code);
|
||||
$name = strtolower($match[2]);
|
||||
|
||||
// required parameters (depends on the tag name)
|
||||
$param = array();
|
||||
$param['style'] = '';
|
||||
if ($name=='img') {
|
||||
$param['alt'] = '';
|
||||
$param['src'] = '';
|
||||
}
|
||||
if ($name=='a') {
|
||||
$param['href'] = '';
|
||||
}
|
||||
|
||||
// read the parameters : nom=valeur
|
||||
$prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)';
|
||||
preg_match_all('/'.$prop.'/is', $code, $match);
|
||||
for($k=0; $k<count($match[0]); $k++)
|
||||
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
||||
|
||||
// read the parameters : nom="valeur"
|
||||
$prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]';
|
||||
preg_match_all('/'.$prop.'/is', $code, $match);
|
||||
for($k=0; $k<count($match[0]); $k++)
|
||||
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
||||
|
||||
// read the parameters : nom='valeur'
|
||||
$prop = "([a-zA-Z0-9_]+)=[']([^']*)[']";
|
||||
preg_match_all('/'.$prop.'/is', $code, $match);
|
||||
for($k=0; $k<count($match[0]); $k++)
|
||||
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
||||
|
||||
// compliance of each parameter
|
||||
$color = "#000000";
|
||||
$border = null;
|
||||
foreach ($param as $key => $val) {
|
||||
$key = strtolower($key);
|
||||
switch($key)
|
||||
{
|
||||
case 'width':
|
||||
unset($param[$key]);
|
||||
$param['style'] .= 'width: '.$val.'px; ';
|
||||
break;
|
||||
|
||||
case 'align':
|
||||
if ($name==='img') {
|
||||
unset($param[$key]);
|
||||
$param['style'] .= 'float: '.$val.'; ';
|
||||
} elseif ($name!=='table') {
|
||||
unset($param[$key]);
|
||||
$param['style'] .= 'text-align: '.$val.'; ';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'valign':
|
||||
unset($param[$key]);
|
||||
$param['style'] .= 'vertical-align: '.$val.'; ';
|
||||
break;
|
||||
|
||||
case 'height':
|
||||
unset($param[$key]);
|
||||
$param['style'] .= 'height: '.$val.'px; ';
|
||||
break;
|
||||
|
||||
case 'bgcolor':
|
||||
unset($param[$key]);
|
||||
$param['style'] .= 'background: '.$val.'; ';
|
||||
break;
|
||||
|
||||
case 'bordercolor':
|
||||
unset($param[$key]);
|
||||
$color = $val;
|
||||
break;
|
||||
|
||||
case 'border':
|
||||
unset($param[$key]);
|
||||
if (preg_match('/^[0-9]+$/isU', $val)) $val = $val.'px';
|
||||
$border = $val;
|
||||
break;
|
||||
|
||||
case 'cellpadding':
|
||||
case 'cellspacing':
|
||||
if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px';
|
||||
break;
|
||||
|
||||
case 'colspan':
|
||||
case 'rowspan':
|
||||
$val = preg_replace('/[^0-9]/isU', '', $val);
|
||||
if (!$val) $val = 1;
|
||||
$param[$key] = $val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// compliance of the border
|
||||
if ($border!==null) {
|
||||
if ($border) $border = 'border: solid '.$border.' '.$color;
|
||||
else $border = 'border: none';
|
||||
|
||||
$param['style'] .= $border.'; ';
|
||||
$param['border'] = $border;
|
||||
}
|
||||
|
||||
// reading styles: decomposition and standardization
|
||||
$styles = explode(';', $param['style']);
|
||||
$param['style'] = array();
|
||||
foreach ($styles as $style) {
|
||||
$tmp = explode(':', $style);
|
||||
if (count($tmp)>1) {
|
||||
$cod = $tmp[0];
|
||||
unset($tmp[0]);
|
||||
$tmp = implode(':', $tmp);
|
||||
$param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp));
|
||||
}
|
||||
}
|
||||
|
||||
// determining the level of table opening, with an added level
|
||||
if (in_array($name, array('ul', 'ol', 'table')) && !$close) {
|
||||
$this->_num++;
|
||||
$this->_level[count($this->_level)] = $this->_num;
|
||||
}
|
||||
|
||||
// get the level of the table containing the element
|
||||
if (!isset($param['num'])) {
|
||||
$param['num'] = $this->_level[count($this->_level)-1];
|
||||
}
|
||||
|
||||
// for closures table: remove a level
|
||||
if (in_array($name, array('ul', 'ol', 'table')) && $close) {
|
||||
unset($this->_level[count($this->_level)-1]);
|
||||
}
|
||||
|
||||
// prepare the parameters
|
||||
if (isset($param['value'])) $param['value'] = $this->_prepareTxt($param['value']);
|
||||
if (isset($param['alt'])) $param['alt'] = $this->_prepareTxt($param['alt']);
|
||||
if (isset($param['title'])) $param['title'] = $this->_prepareTxt($param['title']);
|
||||
if (isset($param['class'])) $param['class'] = $this->_prepareTxt($param['class']);
|
||||
|
||||
// return the new action to do
|
||||
return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a full level of HTML, between an opening and closing corresponding
|
||||
*
|
||||
* @param integer key
|
||||
* @return array actions
|
||||
*/
|
||||
public function getLevel($k)
|
||||
{
|
||||
// if the code does not exist => return empty
|
||||
if (!isset($this->code[$k])) return array();
|
||||
|
||||
// the tag to detect
|
||||
$detect = $this->code[$k]['name'];
|
||||
|
||||
// if it is a text => return
|
||||
if ($detect=='write') {
|
||||
return array($this->code[$k]);
|
||||
}
|
||||
|
||||
//
|
||||
$level = 0; // depth level
|
||||
$end = false; // end of the search
|
||||
$code = array(); // extract code
|
||||
|
||||
// while it's not ended
|
||||
while (!$end) {
|
||||
// current action
|
||||
$row = $this->code[$k];
|
||||
|
||||
// if 'write' => we add the text
|
||||
if ($row['name']=='write') {
|
||||
$code[] = $row;
|
||||
} else { // else, it is a html tag
|
||||
$not = false; // flag for not taking into account the current tag
|
||||
|
||||
// if it is the searched tag
|
||||
if ($row['name']==$detect) {
|
||||
// if we are just at the root level => dont take it
|
||||
if ($level==0) {
|
||||
$not = true;
|
||||
}
|
||||
|
||||
// update the level
|
||||
$level+= ($row['close'] ? -1 : 1);
|
||||
|
||||
// if we are now at the root level => it is the end, and dont take it
|
||||
if ($level==0) {
|
||||
$not = true;
|
||||
$end = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if we can takin into account the current tag => save it
|
||||
if (!$not) {
|
||||
if (isset($row['style']['text-align'])) unset($row['style']['text-align']);
|
||||
$code[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
// it continues as long as there has code to analise
|
||||
if (isset($this->code[$k+1]))
|
||||
$k++;
|
||||
else
|
||||
$end = true;
|
||||
}
|
||||
|
||||
// return the extract
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a part of the HTML code, for error message
|
||||
*
|
||||
* @param integer position
|
||||
* @param integer take before
|
||||
* @param integer take after
|
||||
* @return string part of the html code
|
||||
*/
|
||||
public function getHtmlErrorCode($pos, $before=30, $after=40)
|
||||
{
|
||||
return substr($this->_html, $pos-$before, $before+$after);
|
||||
}
|
||||
}
|
247
html2pdf_v4.03/_class/tcpdfConfig.php
Executable file
247
html2pdf_v4.03/_class/tcpdfConfig.php
Executable file
@ -0,0 +1,247 @@
|
||||
<?php
|
||||
//============================================================+
|
||||
// File name : tcpdf_config.php
|
||||
// Begin : 2004-06-11
|
||||
// Last Update : 2009-09-30
|
||||
//
|
||||
// Description : Configuration file for TCPDF.
|
||||
//
|
||||
// Author: Nicola Asuni
|
||||
//
|
||||
// (c) Copyright:
|
||||
// Nicola Asuni
|
||||
// Tecnick.com s.r.l.
|
||||
// Via Della Pace, 11
|
||||
// 09044 Quartucciu (CA)
|
||||
// ITALY
|
||||
// www.tecnick.com
|
||||
// info@tecnick.com
|
||||
//============================================================+
|
||||
|
||||
/**
|
||||
* Configuration file for TCPDF.
|
||||
* @author Nicola Asuni
|
||||
* @copyright 2004-2008 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com)
|
||||
* Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
|
||||
* @package com.tecnick.tcpdf
|
||||
* @version 4.0.014
|
||||
* @link http://tcpdf.sourceforge.net
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
||||
* @since 2004-10-27
|
||||
*/
|
||||
|
||||
// If you define the constant K_TCPDF_EXTERNAL_CONFIG, the following settings will be ignored.
|
||||
|
||||
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
|
||||
|
||||
define('K_TCPDF_EXTERNAL_CONFIG', true);
|
||||
|
||||
// DOCUMENT_ROOT fix for IIS Webserver
|
||||
if ((!isset($_SERVER['DOCUMENT_ROOT'])) OR (empty($_SERVER['DOCUMENT_ROOT']))) {
|
||||
if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
||||
$_SERVER['DOCUMENT_ROOT'] = str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']))
|
||||
);
|
||||
} elseif (isset($_SERVER['PATH_TRANSLATED'])) {
|
||||
$_SERVER['DOCUMENT_ROOT'] = str_replace(
|
||||
'\\',
|
||||
'/',
|
||||
substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF']))
|
||||
);
|
||||
} else {
|
||||
// define here your DOCUMENT_ROOT path if the previous fails
|
||||
$_SERVER['DOCUMENT_ROOT'] = '/var/www';
|
||||
}
|
||||
}
|
||||
|
||||
// Automatic calculation for the following K_PATH_MAIN constant
|
||||
$kPathMain = str_replace('\\', '/', dirname(__FILE__));
|
||||
$kPathMain = dirname($kPathMain).'/'; // remove the current directory
|
||||
$kPathMain.= '_tcpdf_'.HTML2PDF_USED_TCPDF_VERSION.'/';
|
||||
define('K_PATH_MAIN', $kPathMain);
|
||||
|
||||
// Automatic calculation for the following K_PATH_URL constant
|
||||
if (isset($_SERVER['HTTP_HOST']) AND (!empty($_SERVER['HTTP_HOST']))) {
|
||||
if (isset($_SERVER['HTTPS']) AND (!empty($_SERVER['HTTPS'])) AND strtolower($_SERVER['HTTPS'])!='off') {
|
||||
$kPathUrl = 'https://';
|
||||
} else {
|
||||
$kPathUrl = 'http://';
|
||||
}
|
||||
$kPathUrl .= $_SERVER['HTTP_HOST'];
|
||||
$kPathUrl .= str_replace('\\', '/', substr(K_PATH_MAIN, (strlen($_SERVER['DOCUMENT_ROOT']) - 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* URL path to tcpdf installation folder (http://localhost/tcpdf/).
|
||||
* By default it is automatically calculated but you can also set it as a fixed string to improve performances.
|
||||
*/
|
||||
define('K_PATH_URL', $kPathUrl);
|
||||
|
||||
/**
|
||||
* path for PDF fonts
|
||||
* use K_PATH_MAIN.'fonts/old/' for old non-UTF8 fonts
|
||||
*/
|
||||
define('K_PATH_FONTS', K_PATH_MAIN.'fonts/');
|
||||
|
||||
/**
|
||||
* cache directory for temporary files (full path)
|
||||
*/
|
||||
define('K_PATH_CACHE', K_PATH_MAIN.'cache/');
|
||||
|
||||
/**
|
||||
* cache directory for temporary files (url path)
|
||||
*/
|
||||
define('K_PATH_URL_CACHE', K_PATH_URL.'cache/');
|
||||
|
||||
/**
|
||||
*images directory
|
||||
*/
|
||||
define('K_PATH_IMAGES', K_PATH_MAIN.'images/');
|
||||
|
||||
/**
|
||||
* blank image
|
||||
*/
|
||||
define('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png');
|
||||
|
||||
/**
|
||||
* page format
|
||||
*/
|
||||
define('PDF_PAGE_FORMAT', 'A4');
|
||||
|
||||
/**
|
||||
* page orientation (P=portrait, L=landscape)
|
||||
*/
|
||||
define('PDF_PAGE_ORIENTATION', 'P');
|
||||
|
||||
/**
|
||||
* document creator
|
||||
*/
|
||||
define('PDF_CREATOR', 'HTML2PDF - TCPDF');
|
||||
|
||||
/**
|
||||
* document author
|
||||
*/
|
||||
define('PDF_AUTHOR', 'HTML2PDF - TCPDF');
|
||||
|
||||
/**
|
||||
* header title
|
||||
*/
|
||||
define('PDF_HEADER_TITLE', null);
|
||||
|
||||
/**
|
||||
* header description string
|
||||
*/
|
||||
define('PDF_HEADER_STRING', null);
|
||||
|
||||
/**
|
||||
* image logo
|
||||
*/
|
||||
define('PDF_HEADER_LOGO', null);
|
||||
|
||||
/**
|
||||
* header logo image width [mm]
|
||||
*/
|
||||
define('PDF_HEADER_LOGO_WIDTH', null);
|
||||
|
||||
/**
|
||||
* document unit of measure [pt=point, mm=millimeter, cm=centimeter, in=inch]
|
||||
*/
|
||||
define('PDF_UNIT', 'mm');
|
||||
|
||||
/**
|
||||
* header margin
|
||||
*/
|
||||
define('PDF_MARGIN_HEADER', 0);
|
||||
|
||||
/**
|
||||
* footer margin
|
||||
*/
|
||||
define('PDF_MARGIN_FOOTER', 0);
|
||||
|
||||
/**
|
||||
* top margin
|
||||
*/
|
||||
define('PDF_MARGIN_TOP', 0);
|
||||
|
||||
/**
|
||||
* bottom margin
|
||||
*/
|
||||
define('PDF_MARGIN_BOTTOM', 0);
|
||||
|
||||
/**
|
||||
* left margin
|
||||
*/
|
||||
define('PDF_MARGIN_LEFT', 0);
|
||||
|
||||
/**
|
||||
* right margin
|
||||
*/
|
||||
define('PDF_MARGIN_RIGHT', 0);
|
||||
|
||||
/**
|
||||
* default main font name
|
||||
*/
|
||||
define('PDF_FONT_NAME_MAIN', 'helvetica');
|
||||
|
||||
/**
|
||||
* default main font size
|
||||
*/
|
||||
define('PDF_FONT_SIZE_MAIN', 10);
|
||||
|
||||
/**
|
||||
* default data font name
|
||||
*/
|
||||
define('PDF_FONT_NAME_DATA', 'helvetica');
|
||||
|
||||
/**
|
||||
* default data font size
|
||||
*/
|
||||
define('PDF_FONT_SIZE_DATA', 8);
|
||||
|
||||
/**
|
||||
* default monospaced font name
|
||||
*/
|
||||
define('PDF_FONT_MONOSPACED', 'courier');
|
||||
|
||||
/**
|
||||
* ratio used to adjust the conversion of pixels to user units
|
||||
*/
|
||||
define('PDF_IMAGE_SCALE_RATIO', 1);
|
||||
|
||||
/**
|
||||
* magnification factor for titles
|
||||
*/
|
||||
define('HEAD_MAGNIFICATION', 1);
|
||||
|
||||
/**
|
||||
* height of cell repect font height
|
||||
*/
|
||||
define('K_CELL_HEIGHT_RATIO', 1);
|
||||
|
||||
/**
|
||||
* title magnification respect main font size
|
||||
*/
|
||||
define('K_TITLE_MAGNIFICATION', 1);
|
||||
|
||||
/**
|
||||
* reduction factor for small font
|
||||
*/
|
||||
define('K_SMALL_RATIO', 2/3);
|
||||
|
||||
/**
|
||||
* set to true to enable the special procedure used to avoid the overlappind of symbols on Thai language
|
||||
*/
|
||||
define('K_THAI_TOPCHARS', true);
|
||||
|
||||
/**
|
||||
* if true allows to call TCPDF methods using HTML syntax
|
||||
* IMPORTANT: For security reason, disable this feature if you are printing user HTML content.
|
||||
*/
|
||||
define('K_TCPDF_CALLS_IN_HTML', false);
|
||||
}
|
||||
|
||||
//============================================================+
|
||||
// END OF FILE
|
||||
//============================================================+
|
Reference in New Issue
Block a user