Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,405 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf;
/**
* Class CssConverter
*/
class CssConverter
{
private $htmlColor = array(); // list of the HTML colors
/**
* fontsize ratios
* @var float[]
*/
private $fontSizeRatio = [
'smaller' => 0.8,
'larger' => 1.25,
'xx-small' => 0.512,
'x-small' => 0.64,
'small' => 0.8,
'medium' => 1.,
'large' => 1.25,
'x-large' => 1.5625,
'xx-large' => 1.953125,
];
public function __construct()
{
$this->htmlColor = \TCPDF_COLORS::$webcolor;
}
/**
* convert a distance to mm
*
* @param string $css distance to convert
* @param float $old parent distance
*
* @return float
*/
public function convertToMM($css, $old = 0.)
{
$css = trim($css);
if (preg_match('/^[0-9\.\-]+$/isU', $css)) {
$css.= 'px';
}
if (preg_match('/^[0-9\.\-]+px$/isU', $css)) {
$css = 25.4/96. * str_replace('px', '', $css);
} elseif (preg_match('/^[0-9\.\-]+pt$/isU', $css)) {
$css = 25.4/72. * str_replace('pt', '', $css);
} elseif (preg_match('/^[0-9\.\-]+in$/isU', $css)) {
$css = 25.4 * str_replace('in', '', $css);
} elseif (preg_match('/^[0-9\.\-]+mm$/isU', $css)) {
$css = 1.*str_replace('mm', '', $css);
} elseif (preg_match('/^[0-9\.\-]+%$/isU', $css)) {
$css = 1.*$old*str_replace('%', '', $css)/100.;
} else {
$css = null;
}
return $css;
}
/**
* @param string $css font size to convert
* @param float $parent parent font size
* @return float
*/
public function convertFontSize($css, $parent = 0.)
{
$css = trim($css);
if (array_key_exists($css, $this->fontSizeRatio)) {
$css = ($this->fontSizeRatio[$css] * $parent).'mm';
}
return $this->convertToMM($css, $parent);
}
/**
* convert a css radius
*
* @access public
* @param string $css
* @return float $value
*/
public function convertToRadius($css)
{
// explode the value
$css = explode(' ', $css);
foreach ($css as $k => $v) {
$v = trim($v);
if ($v !== '') {
$v = $this->convertToMM($v, 0);
if ($v !== null) {
$css[$k] = $v;
} else {
unset($css[$k]);
}
} else {
unset($css[$k]);
}
}
return array_values($css);
}
/**
* convert a css color to an RGB array
*
* @param string $css
* @param &boolean $res
*
* @return array (r, g, b)
*/
public function convertToColor($css, &$res)
{
// prepare the value
$css = trim($css);
$res = true;
// if transparent => return null
if (strtolower($css) === 'transparent') {
return array(null, null, null);
}
// HTML color
if (isset($this->htmlColor[strtolower($css)])) {
$css = $this->htmlColor[strtolower($css)];
$r = floatVal(hexdec(substr($css, 0, 2)));
$g = floatVal(hexdec(substr($css, 2, 2)));
$b = floatVal(hexdec(substr($css, 4, 2)));
return array($r, $g, $b);
}
// like #FFFFFF
if (preg_match('/^#[0-9A-Fa-f]{6}$/isU', $css)) {
$r = floatVal(hexdec(substr($css, 1, 2)));
$g = floatVal(hexdec(substr($css, 3, 2)));
$b = floatVal(hexdec(substr($css, 5, 2)));
return array($r, $g, $b);
}
// like #FFF
if (preg_match('/^#[0-9A-F]{3}$/isU', $css)) {
$r = floatVal(hexdec(substr($css, 1, 1).substr($css, 1, 1)));
$g = floatVal(hexdec(substr($css, 2, 1).substr($css, 2, 1)));
$b = floatVal(hexdec(substr($css, 3, 1).substr($css, 3, 1)));
return array($r, $g, $b);
}
// like rgb(100, 100, 100)
$sub = '[\s]*([0-9%\.]+)[\s]*';
if (preg_match('/rgb\('.$sub.','.$sub.','.$sub.'\)/isU', $css, $match)) {
$r = $this->convertSubColor($match[1]);
$g = $this->convertSubColor($match[2]);
$b = $this->convertSubColor($match[3]);
return array($r * 255., $g * 255., $b * 255.);
}
// like cmyk(100, 100, 100, 100)
$sub = '[\s]*([0-9%\.]+)[\s]*';
if (preg_match('/cmyk\('.$sub.','.$sub.','.$sub.','.$sub.'\)/isU', $css, $match)) {
$c = $this->convertSubColor($match[1]);
$m = $this->convertSubColor($match[2]);
$y = $this->convertSubColor($match[3]);
$k = $this->convertSubColor($match[4]);
return array($c * 100., $m * 100., $y * 100., $k * 100.);
}
$res = false;
return array(0., 0., 0.);
}
/**
* color value to convert
*
* @access protected
* @param string $c
* @return float $c 0.->1.
*/
protected function convertSubColor($c)
{
if (substr($c, -1) === '%') {
$c = floatVal(substr($c, 0, -1)) / 100.;
} else {
$c = floatVal($c);
if ($c > 1) {
$c = $c / 255.;
}
}
return $c;
}
/**
* Analyse a background
*
* @param string $css css background properties
* @param &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties)
*
* @return void
*/
public function convertBackground($css, &$value)
{
// is there a image ?
$text = '/url\(([^)]*)\)/isU';
if (preg_match($text, $css, $match)) {
// get the image
$value['image'] = $this->convertBackgroundImage($match[0]);
// remove if from the css properties
$css = preg_replace($text, '', $css);
$css = preg_replace('/[\s]+/', ' ', $css);
}
// protect some spaces
$css = preg_replace('/,[\s]+/', ',', $css);
// explode the values
$css = explode(' ', $css);
// background position to parse
$pos = '';
// foreach value
foreach ($css as $val) {
// try to parse the value as a color
$ok = false;
$color = $this->convertToColor($val, $ok);
// if ok => it is a color
if ($ok) {
$value['color'] = $color;
// else if transparent => no coloàr
} elseif ($val === 'transparent') {
$value['color'] = null;
// else
} else {
// try to parse the value as a repeat
$repeat = $this->convertBackgroundRepeat($val);
// if ok => it is repeat
if ($repeat) {
$value['repeat'] = $repeat;
// else => it could only be a position
} else {
$pos.= ($pos ? ' ' : '').$val;
}
}
}
// if we have a position to parse
if ($pos) {
// try to read it
$pos = $this->convertBackgroundPosition($pos, $ok);
if ($ok) {
$value['position'] = $pos;
}
}
}
/**
* Parse a background color
*
* @param string $css
*
* @return string|null $value
*/
public function convertBackgroundColor($css)
{
$res = null;
if ($css === 'transparent') {
return null;
}
return $this->convertToColor($css, $res);
}
/**
* Parse a background image
*
* @param string $css
*
* @return string|null $value
*/
public function convertBackgroundImage($css)
{
if ($css === 'none') {
return null;
}
if (preg_match('/^url\(([^)]*)\)$/isU', $css, $match)) {
return $match[1];
}
return null;
}
/**
* Parse a background position
*
* @param string $css
* @param boolean &$res flag if convert is ok or not
*
* @return array (x, y)
*/
public function convertBackgroundPosition($css, &$res)
{
// init the res
$res = false;
// explode the value
$css = explode(' ', $css);
// we must have 2 values. if 0 or >2 : error. if 1 => put center for 2
if (count($css)<2) {
if (!$css[0]) {
return null;
}
$css[1] = 'center';
}
if (count($css)>2) {
return null;
}
// prepare the values
$x = 0;
$y = 0;
$res = true;
// convert the first value
if ($css[0] === 'left') {
$x = '0%';
} elseif ($css[0] === 'center') {
$x = '50%';
} elseif ($css[0] === 'right') {
$x = '100%';
} elseif ($css[0] === 'top') {
$y = '0%';
} elseif ($css[0] === 'bottom') {
$y = '100%';
} elseif (preg_match('/^[-]?[0-9\.]+%$/isU', $css[0])) {
$x = $css[0];
} elseif ($this->convertToMM($css[0])) {
$x = $this->convertToMM($css[0]);
} else {
$res = false;
}
// convert the second value
if ($css[1] === 'left') {
$x = '0%';
} elseif ($css[1] === 'right') {
$x = '100%';
} elseif ($css[1] === 'top') {
$y = '0%';
} elseif ($css[1] === 'center') {
$y = '50%';
} elseif ($css[1] === 'bottom') {
$y = '100%';
} elseif (preg_match('/^[-]?[0-9\.]+%$/isU', $css[1])) {
$y = $css[1];
} elseif ($this->convertToMM($css[1])) {
$y = $this->convertToMM($css[1]);
} else {
$res = false;
}
// return the values
return array($x, $y);
}
/**
* Parse a background repeat
*
* @param string $css
*
* @return array|null background repeat as array
*/
public function convertBackgroundRepeat($css)
{
switch ($css) {
case 'repeat':
return array(true, true);
case 'repeat-x':
return array(true, false);
case 'repeat-y':
return array(false, true);
case 'no-repeat':
return array(false, false);
}
return null;
}
}

View File

@ -0,0 +1,143 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Debug;
/**
* Class Debug
*/
class Debug implements DebugInterface
{
/**
* @var float
*/
protected $startTime;
/**
* @var float
*/
protected $lastTime;
/**
* @var int
*/
protected $level = 0;
/**
* @var bool
*/
protected $htmlOutput;
/**
* Debug constructor
*
* @param bool $htmlOutput
*/
public function __construct($htmlOutput = true)
{
$this->htmlOutput = $htmlOutput;
}
/**
* display a debug line
*
* @param string $name
* @param string $timeTotal
* @param string $timeStep
* @param string $memoryUsage
* @param string $memoryPeak
*
* @return void
*/
protected function displayLine($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak)
{
$output =
str_pad($name, 30, ' ', STR_PAD_RIGHT).
str_pad($timeTotal, 12, ' ', STR_PAD_LEFT).
str_pad($timeStep, 12, ' ', STR_PAD_LEFT).
str_pad($memoryUsage, 15, ' ', STR_PAD_LEFT).
str_pad($memoryPeak, 15, ' ', STR_PAD_LEFT);
if ($this->htmlOutput) {
$output = '<pre style="padding:0; margin:0">'.$output.'</pre>';
}
echo $output."\n";
}
/**
* Start the debugger
*
* @return Debug
*/
public function start()
{
$time = microtime(true);
$this->startTime = $time;
$this->lastTime = $time;
$this->displayLine('step', 'time', 'delta', 'memory', 'peak');
$this->addStep('Init debug');
return $this;
}
/**
* stop the debugger
*
* @return Debug
*/
public function stop()
{
$this->addStep('Before output');
return $this;
}
/**
* add a debug step
*
* @param string $name step name
* @param boolean $level (true=up, false=down, null=nothing to do)
*
* @return Debug
*/
public function addStep($name, $level = null)
{
// if true : UP
if ($level === true) {
$this->level++;
}
$time = microtime(true);
$usage = memory_get_usage();
$peak = memory_get_peak_usage();
$type = ($level === true ? ' Begin' : ($level === false ? ' End' : ''));
$this->displayLine(
str_repeat(' ', $this->level) . $name . $type,
number_format(($time - $this->startTime)*1000, 1, '.', ' ').' ms',
number_format(($time - $this->lastTime)*1000, 1, '.', ' ').' ms',
number_format($usage/1024, 1, '.', ' ').' Ko',
number_format($peak/1024, 1, '.', ' ').' Ko'
);
$this->lastTime = $time;
// it false : DOWN
if ($level === false) {
$this->level--;
}
return $this;
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Html2Pdf Library - Debug
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Debug;
interface DebugInterface
{
/**
* Start the debugger
*
* @return DebugInterface
*/
public function start();
/**
* Stop the debugger
*
* @return DebugInterface
*/
public function stop();
/**
* add a debug step
*
* @param string $name step name
* @param boolean $level (true=up, false=down, null=nothing to do)
*
* @return DebugInterface
*/
public function addStep($name, $level = null);
}

View File

@ -0,0 +1,152 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Exception Formatter
*/
class ExceptionFormatter
{
/**
* the text message
* @var string
*/
protected $message;
/**
* the html message
* @var string
*/
protected $htmlMessage;
/**
* PHP Constructor
*
* @param Html2PdfException $e the exception to format
*
* @return ExceptionFormatter
*/
public function __construct(Html2PdfException $e)
{
$data = $this->getAdditionalData($e);
$this->buildTextMessage($e, $data);
$this->buildHtmlMessage($e, $data);
}
/**
* get the txt message
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* get tht HTML message
*
* @return string
*/
public function getHtmlMessage()
{
return $this->htmlMessage;
}
/**
* get the additional data from the exception
*
* @param Html2PdfException $e the exception to display
*
* @return array
*/
protected function getAdditionalData(Html2PdfException $e)
{
$data = array();
// read the error
switch ($e->getCode()) {
case HtmlParsingException::ERROR_CODE:
/** @var HtmlParsingException $e */
$data['invalid tag'] = $e->getInvalidTag();
$data['html line'] = $e->getHtmlLine();
break;
case ImageException::ERROR_CODE:
/** @var ImageException $e */
$data['image src'] = $e->getImage();
break;
case LongSentenceException::ERROR_CODE:
/** @var LongSentenceException $e */
$data['sentence'] = $e->getSentence();
$data['box width'] = $e->getWidthBox();
$data['length'] = $e->getLength();
break;
case TableException::ERROR_CODE:
case Html2PdfException::ERROR_CODE:
default:
break;
}
return $data;
}
/**
* Build the text message
*
* @param Html2PdfException $e the exception of the error
* @param array $data additionnal data
*
* @return void
*/
protected function buildTextMessage(Html2PdfException $e, $data)
{
$this->message = 'Html2Pdf Error ['.$e->getCode().']'."\n";
$this->message.= $e->getMessage()."\n";
$this->message.= ' File: '.$e->getFile()."\n";
$this->message.= ' Line: '.$e->getLine()."\n";
if (!empty($data)) {
foreach ($data as $key => $value) {
$this->message .= ' '.ucwords($key).': '.trim($value)."\n";
}
}
}
/**
* build the html message
*
* @param Html2PdfException $e the exception of the error
* @param array $data additional data
*
* @return void
*/
protected function buildHtmlMessage(Html2PdfException $e, $data)
{
$this->htmlMessage = '<span style="color: #A00; font-weight: bold;">';
$this->htmlMessage.= 'Html2Pdf Error ['.$e->getCode().']';
$this->htmlMessage.= '</span><br />'."\n";
$this->htmlMessage.= htmlentities($e->getMessage())."<br />\n";
$this->htmlMessage.= ' File: '.$e->getFile()."<br />\n";
$this->htmlMessage.= ' Line: '.$e->getLine()."<br />\n";
if (!empty($data)) {
foreach ($data as $key => $value) {
$this->htmlMessage .= ' '.ucwords($key).': '.trim(htmlentities($value))."<br />\n";
}
}
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Html2Pdf Exception
*/
class Html2PdfException extends \Exception
{
/**
* ERROR CODE 0
* @var int
*/
const ERROR_CODE = 0;
/**
* Construct the exception.
*
* @param string $message The Exception message to throw.
*
* @return Html2PdfException
*/
public function __construct($message)
{
parent::__construct($message, static::ERROR_CODE);
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Html Parsing Exception
*/
class HtmlParsingException extends Html2PdfException
{
/**
* ERROR CODE 1
* @var int
*/
const ERROR_CODE = 1;
/**
* invalid tag
* @var string
*/
protected $invalidTag;
/**
* the line in HTML data where the error occurred
* @var int
*/
protected $htmlLine;
/**
* set the invalid Tag
*
* @param string $value the value
*
* @return HtmlParsingException
*/
public function setInvalidTag($value)
{
$this->invalidTag = $value;
return $this;
}
/**
* get the invalid Tag
*
* @return string
*/
public function getInvalidTag()
{
return $this->invalidTag;
}
/**
* @param int $lineNumber the value
*
* @return HtmlParsingException
*/
public function setHtmlLine($lineNumber)
{
$this->htmlLine = $lineNumber;
return $this;
}
/**
* @return int
*/
public function getHtmlLine()
{
return $this->htmlLine;
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Image Exception
*/
class ImageException extends Html2PdfException
{
/**
* ERROR CODE 2
* @var int
*/
const ERROR_CODE = 2;
/**
* asked unknown image
* @var string
*/
protected $image;
/**
* set the image in error
*
* @param string $value the value
*
* @return ImageException
*/
public function setImage($value)
{
$this->image = $value;
return $this;
}
/**
* get the image in error
*
* @return string
*/
public function getImage()
{
return $this->image;
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Table Exception
*/
class LocaleException extends Html2PdfException
{
/**
* ERROR CODE 5
* @var int
*/
const ERROR_CODE = 5;
/**
* @var string
*/
protected $localCode;
/**
* set the code
*
* @param string $localCode
*
* @return $this
*/
public function setLocaleCode($localCode)
{
$this->localCode = $localCode;
return $this;
}
/**
* get the local code
*
* @return string
*/
public function getLocalCode()
{
return $this->localCode;
}
}

View File

@ -0,0 +1,115 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Long Sentence Exception
*/
class LongSentenceException extends Html2PdfException
{
/**
* ERROR CODE 3
* @var int
*/
const ERROR_CODE = 3;
/**
* the sentence
* @var string
*/
protected $sentence;
/**
* the width of the box
* @var string
*/
protected $widthBox;
/**
* the length of the sentence
* @var string
*/
protected $length;
/**
* set the sentence
*
* @param string $value the value
*
* @return LongSentenceException
*/
public function setSentence($value)
{
$this->sentence = $value;
return $this;
}
/**
* get the image in error
*
* @return string
*/
public function getSentence()
{
return $this->sentence;
}
/**
* set the width of the box that contain the sentence
*
* @param string $value the value
*
* @return LongSentenceException
*/
public function setWidthBox($value)
{
$this->widthBox = $value;
return $this;
}
/**
* get the image in error
*
* @return string
*/
public function getWidthBox()
{
return $this->widthBox;
}
/**
* set the length
*
* @param string $value the value
*
* @return LongSentenceException
*/
public function setLength($value)
{
$this->length = $value;
return $this;
}
/**
* get the length
*
* @return string
*/
public function getLength()
{
return $this->length;
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* Html2Pdf Library - Exception class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Exception;
/**
* Table Exception
*/
class TableException extends Html2PdfException
{
/**
* ERROR CODE 4
* @var int
*/
const ERROR_CODE = 4;
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Extension;
use Spipu\Html2Pdf\Tag\TagInterface;
/**
* Class AbstractExtension
*/
abstract class AbstractExtension implements ExtensionInterface
{
/**
* @var array
*/
protected $tagDefinitions = array();
/**
* {@inheritDoc}
*/
public function getTags()
{
if (empty($this->tagDefinitions)) {
$this->tagDefinitions = $this->initTags();
}
return $this->tagDefinitions;
}
/**
* Init the tags
*
* @return TagInterface[]
*/
abstract protected function initTags();
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Extension\Core;
use Spipu\Html2Pdf\Extension\AbstractExtension;
use Spipu\Html2Pdf\Tag\Html;
/**
* Class HtmlExtension
*/
class HtmlExtension extends AbstractExtension
{
/**
* {@inheritDoc}
*/
public function getName()
{
return 'core_html';
}
/**
* @inheritdoc
*/
protected function initTags()
{
return array(
new Html\Address(),
new Html\B(),
new Html\Big(),
new Html\Bookmark(),
new Html\Cite(),
new Html\Del(),
new Html\Em(),
new Html\Font(),
new Html\I(),
new Html\Ins(),
new Html\Label(),
new Html\S(),
new Html\Samp(),
new Html\Small(),
new Html\Span(),
new Html\Strong(),
new Html\Sub(),
new Html\Sup(),
new Html\U(),
);
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Extension\Core;
use Spipu\Html2Pdf\Extension\AbstractExtension;
use Spipu\Html2Pdf\SvgDrawer;
use Spipu\Html2Pdf\Tag\Svg;
/**
* Class SvgExtension
*/
class SvgExtension extends AbstractExtension
{
/**
* @var SvgDrawer
*/
private $svgDrawer;
/**
* SvgExtension constructor.
*
* @param SvgDrawer $svgDrawer
*/
public function __construct(SvgDrawer $svgDrawer)
{
$this->svgDrawer = $svgDrawer;
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'core_svg';
}
/**
* @inheritdoc
*/
protected function initTags()
{
return array(
new Svg\Circle($this->svgDrawer),
new Svg\Ellipse($this->svgDrawer),
new Svg\G($this->svgDrawer),
new Svg\Line($this->svgDrawer),
new Svg\Path($this->svgDrawer),
new Svg\Polygon($this->svgDrawer),
new Svg\Polyline($this->svgDrawer),
new Svg\Rect($this->svgDrawer),
);
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Extension;
/**
* Interface ExtensionInterface
*/
interface ExtensionInterface
{
/**
* Get the extension's name
*
* @return string
*/
public function getName();
/**
* @return array()
*/
public function getTags();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,116 @@
<?php
/**
* Html2Pdf Library - Locale
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf;
use Spipu\Html2Pdf\Exception\LocaleException;
class 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
*
* @param string $code
*
* @return void
* @throws LocaleException
*/
public static function load($code)
{
if (self::$directory === null) {
self::$directory = __DIR__ . '/locale/';
}
// must be in lower case
$code = strtolower($code);
// must be [a-z-0-9]
if (!preg_match('/^([a-z0-9]+)$/isU', $code)) {
$e = new LocaleException(
'invalid language code'
);
$e->setLocaleCode($code);
throw $e;
}
// 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)) {
$e = new LocaleException(
'unknown language code. You can create the locale file and push it on the Html2Pdf GitHub project.'
);
$e->setLocaleCode($code);
throw $e;
}
// load the file
self::$list = array();
$handle = fopen($file, 'r');
while (!feof($handle)) {
$line = fgetcsv($handle);
if (!is_array($line) || count($line) !=2) {
continue;
}
self::$list[trim($line[0])] = trim($line[1]);
}
fclose($handle);
}
/**
* clean the locale
*
* @return void
*/
public static function clean()
{
self::$code = null;
self::$list = array();
}
/**
* get a text
*
* @param string $key
* @param string $default
*
* @return string
*/
public static function get($key, $default = '######')
{
return (isset(self::$list[$key]) ? self::$list[$key] : $default);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,473 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Parsing;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
/**
* Class Html
*/
class Html
{
const HTML_TAB = ' ';
/**
* @var TagParser
*/
protected $tagParser;
/**
* @var TextParser
*/
protected $textParser;
/**
* are we in a pre ?
* @var boolean
*/
protected $tagPreIn = false;
/**
* parsed HTML code
* @var Node[]
*/
public $code = array();
/**
* main constructor
*
* @param TextParser $textParser
*/
public function __construct(TextParser $textParser)
{
$this->textParser = $textParser;
$this->tagParser = new TagParser($this->textParser);
$this->code = array();
}
/**
* Get the list of the codes, but cloned
*
* @return Node[]
*/
public function getCloneCodes()
{
$codes = array();
foreach ($this->code as $key => $code) {
$codes[$key] = clone $code;
}
return $codes;
}
/**
* parse the HTML code
*
* @param Token[] $tokens A list of tokens to parse
*
* @throws HtmlParsingException
*/
public function parse($tokens)
{
$parents = array();
// flag : are we in a <pre> Tag ?
$this->tagPreIn = false;
/**
* all the actions to do
* @var Node[] $actions
*/
$actions = array();
// get the actions from the html tokens
foreach ($tokens as $token) {
if ($token->getType() === 'code') {
$actions = array_merge($actions, $this->getTagAction($token, $parents));
} elseif ($token->getType() === 'txt') {
$actions = array_merge($actions, $this->getTextAction($token));
}
}
// for each identified 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'
);
// list of the tags to move space
$tagsToSpace = array(
'span', 'font', 'label',
'strong', 'b',
'address', 'cite', 'em', 'i', 'samp',
'cite', 's',
'ins', 'u',
'big', 'small', 'sub', 'sup'
);
// foreach action
$nb = count($actions);
for ($k = 0; $k < $nb; $k++) {
// if it is a Text
if ($actions[$k]->getName() !== 'write') {
continue;
}
// if the tag before the text is a tag to clean => ltrim on the text
if ($k>0) {
if (in_array($actions[$k - 1]->getName(), $tagsToClean)) {
$actions[$k]->setParam('txt', ltrim($actions[$k]->getParam('txt')));
}
}
if ($k < $nb - 1) {
// if the tag after the text is a tag to clean => rtrim on the text
if (in_array($actions[$k + 1]->getName(), $tagsToClean)) {
$actions[$k]->setParam('txt', rtrim($actions[$k]->getParam('txt')));
}
// if the tag after the text is a tag with space to move => move the space to the next write
if (in_array($actions[$k + 1]->getName(), $tagsToSpace)) {
if (substr($actions[$k]->getParam('txt'), -1) == ' ') {
$actions[$k]->setParam('txt', rtrim($actions[$k]->getParam('txt')));
for ($subK = $k+2; $subK < $nb; $subK++) {
if ($actions[$subK]->getName() === 'write') {
$actions[$subK]->setParam('txt', ' '.ltrim($actions[$subK]->getParam('txt')));
break;
}
}
}
}
}
// if the text is empty => remove the action
if (!strlen($actions[$k]->getParam('txt'))) {
unset($actions[$k]);
}
}
// if we are not on the level 0 => HTML validator ERROR
if (count($parents)) {
if (count($parents)>1) {
$errorMsg = 'The following tags have not been closed:';
} else {
$errorMsg = 'The following tag has not been closed:';
}
$e = new HtmlParsingException($errorMsg.' '.implode(', ', $parents));
$e->setInvalidTag($parents[0]);
throw $e;
}
$this->verifyMustContain($actions, 'thead', 'tr');
$this->verifyMustContain($actions, 'tfoot', 'tr');
// save the actions to do
$this->code = array_values($actions);
}
/**
* Verify some tags that must contain other tags
*
* @param Node[] $actions
* @param string $mainTag
* @param string $mustTag
*
* @return bool
* @throws HtmlParsingException
*/
protected function verifyMustContain(&$actions, $mainTag, $mustTag)
{
$inMainTag = 0;
$foundMustTag = false;
foreach ($actions as $action) {
if ($action->getName() == $mainTag && !$action->isClose()) {
$inMainTag++;
$foundMustTag = false;
}
if ($action->getName() == $mustTag && $inMainTag > 0) {
$foundMustTag = true;
}
if ($action->getName() == $mainTag && $action->isClose()) {
if (!$foundMustTag) {
$exception = new HtmlParsingException(
"The tag [$mainTag] must contain at least one tag [$mustTag]"
);
$exception->setInvalidTag($action->getName());
$exception->setHtmlLine($action->getLine());
throw $exception;
}
$inMainTag--;
}
}
return true;
}
/**
* TODO remove the reference on the $parents variable
*
* @param Token $token
* @param array $parents
*
* @return array
* @throws HtmlParsingException
*/
protected function getTagAction(Token $token, &$parents)
{
// tag that can be not closed
$tagsNotClosed = array(
'br', 'hr', 'img', 'col',
'input', 'link', 'option',
'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline'
);
// analyze the HTML code
$node = $this->tagParser->analyzeTag($token->getData());
// save the current position in the HTML code
$node->setLine($token->getLine());
$actions = array();
// if the tag must be closed
if (!in_array($node->getName(), $tagsNotClosed)) {
// if it is a closure tag
if ($node->isClose()) {
// HTML validation
if (count($parents) < 1) {
$e = new HtmlParsingException('Too many tag closures found for ['.$node->getName().']');
$e->setInvalidTag($node->getName());
$e->setHtmlLine($token->getLine());
throw $e;
} elseif (end($parents) != $node->getName()) {
$e = new HtmlParsingException('Tags are closed in a wrong order for ['.$node->getName().']');
$e->setInvalidTag($node->getName());
$e->setHtmlLine($token->getLine());
throw $e;
} else {
array_pop($parents);
}
} else {
// if it is an auto-closed tag
if ($node->isAutoClose()) {
// save the opened tag
$actions[] = $node;
// prepare the closed tag
$node = clone $node;
$node->setParams(array());
$node->setClose(true);
} else {
// else: add a child for validation
array_push($parents, $node->getName());
}
}
// if it is a <pre> tag (or <code> tag) not auto-closed => update the flag
if (($node->getName() === 'pre' || $node->getName() === 'code') && !$node->isAutoClose()) {
$this->tagPreIn = !$node->isClose();
}
}
// save the actions to convert
$actions[] = $node;
return $actions;
}
/**
* get the Text action
*
* @param Token $token
*
* @return array
*/
protected function getTextAction(Token $token)
{
// action to use for each line of the content of a <pre> Tag
$tagPreBr = new Node('br', array('style' => array(), 'num' => 0), false);
$actions = array();
// if we are not in a <pre> tag
if (!$this->tagPreIn) {
// save the action
$actions[] = new Node('write', array('txt' => $this->textParser->prepareTxt($token->getData())), false);
} else { // else (if we are in a <pre> tag)
// prepare the text
$data = str_replace("\r", '', $token->getData());
$lines = explode("\n", $data);
// foreach line of the text
foreach ($lines as $k => $txt) {
// transform the line
$txt = str_replace("\t", self::HTML_TAB, $txt);
$txt = str_replace(' ', '&nbsp;', $txt);
// add a break line
if ($k > 0) {
$actions[] = clone $tagPreBr;
}
// save the action
$actions[] = new Node('write', array('txt' => $this->textParser->prepareTxt($txt, false)), false);
}
}
return $actions;
}
/**
* get a full level of HTML, between an opening and closing corresponding
*
* @param integer $k
* @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]->getName();
// 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
/** @var Node $node */
$node = $this->code[$k];
// if 'write' => we add the text
if ($node->getName() === 'write') {
$code[] = $node;
} 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 ($node->getName() == $detect) {
// if we are just at the root level => dont take it
if ($level == 0) {
$not = true;
}
// update the level
$level += ($node->isClose() ? -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 take into account the current tag => save it
if (!$not) {
$code[] = $node;
}
}
// it continues as long as there has code to analyze
if (isset($this->code[$k + 1])) {
$k++;
} else {
$end = true;
}
}
// return the extract
return $code;
}
/**
* prepare the HTML
*
* @param string $html
*
* @return string
*/
public function prepareHtml($html)
{
// if it is a real html page, we have to convert it
if (preg_match('/<body/isU', $html)) {
$html = $this->getHtmlFromRealPage($html);
}
// replace some constants
$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);
return $html;
}
/**
* convert the HTML of a real page, to a code adapted to Html2Pdf
*
* @param string $html HTML code of a real page
* @return string HTML adapted to Html2Pdf
*/
protected function getHtmlFromRealPage($html)
{
// set body tag to lower case
$html = str_replace('<BODY', '<body', $html);
$html = str_replace('</BODY', '</body', $html);
// explode from the body tag. If no body tag => end
$res = explode('<body', $html);
// the html content is between body tag openning and closing
$content = '<page'.$res[1];
$content = explode('</body', $content);
$content = $content[0].'</page>';
// extract the link tags from the original html
// and add them before the content
preg_match_all('/<link ([^>]*)[\/]?>/isU', $html, $match);
foreach ($match[1] as $src) {
$content = '<link '.$src.'/>'.$content;
}
// extract the css style tags from the original html
// and add them before the content
preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
foreach ($match[0] as $src) {
$content = $src.$content;
}
return $content;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* Html2Pdf Library - parsing Html class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Parsing;
/**
* Class HtmlLexer
*/
class HtmlLexer
{
/**
* Tokenize the HTML code
*
* @param string $html HTML code to tokenize
*
* @return Token[]
*/
public function tokenize($html)
{
// initialise the array
$tokens = array();
// regexp to separate the tags from the texts
$reg = '/(<\/?\w[^<>]*>)|([^<]+|<)/is';
$commentRegex = '/(<!--.*-->)/isU';
// last match found
$str = '';
$offset = 0;
$line = 1;
$length = strlen($html);
// As it finds a match
while ($offset < $length) {
if (strpos($html, '<!--', $offset) === $offset
&& preg_match($commentRegex, $html, $match, PREG_OFFSET_CAPTURE, $offset)
) {
$line += substr_count($match[1][0], "\n");
$offset = $match[0][1] + strlen($match[0][0]);
continue;
}
preg_match($reg, $html, $parse, PREG_OFFSET_CAPTURE, $offset);
// if it is a tag
if ($parse[1][0]) {
// save the previous text if it exists
if ($str !== '') {
$tokens[] = new Token('txt', $str);
}
// save the tag, with the offset
$tokens[] = new Token('code', trim($parse[1][0]), $line);
$line += substr_count($parse[1][0], "\n");
// init the current text
$str = '';
} else { // else (if it is a text)
// add the new text to the current text
$str .= $parse[2][0];
$line += substr_count($parse[2][0], "\n");
}
// 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 !== '') {
$tokens[] = new Token('txt', $str);
}
return $tokens;
}
}

View File

@ -0,0 +1,180 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF convertor
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Parsing;
/**
* Class Node
*
* Represent an DOM node in the document
*/
class Node
{
/**
* @var string
*/
private $name;
/**
* @var array
*/
private $params;
/**
* @var bool
*/
private $close;
/**
* @var bool
*/
private $autoClose;
/**
* @var int
*/
private $line;
/**
* @param string $name
* @param array $params
* @param bool $close
* @param bool $autoClose
*/
public function __construct($name, $params, $close, $autoClose = false)
{
$this->setName($name);
$this->setParams($params);
$this->setClose($close);
$this->setAutoClose($autoClose);
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return array
*/
public function getParams()
{
return $this->params;
}
/**
* @param string $key
* @param mixed $default
*
* @return null
*/
public function getParam($key, $default = null)
{
if (array_key_exists($key, $this->params)) {
return $this->params[$key];
}
return $default;
}
/**
* Get a style
* @param string $key
* @param string|null $default
*
* @return string|null
*/
public function getStyle($key, $default = null)
{
$styles = $this->getParam('style', []);
if (array_key_exists($key, $styles)) {
return $styles[$key];
}
return $default;
}
/**
* @param string $key
* @param mixed $value
*
* @return mixed
*/
public function setParam($key, $value)
{
return $this->params[$key] = $value;
}
/**
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
/**
* @return bool
*/
public function isClose()
{
return $this->close;
}
/**
* @param bool $close
*/
public function setClose($close)
{
$this->close = (bool) $close;
}
/**
* @return bool
*/
public function isAutoClose()
{
return $this->autoClose;
}
/**
* @param $autoClose
*/
public function setAutoClose($autoClose)
{
$this->autoClose = (bool) $autoClose;
}
/**
* @return int
*/
public function getLine()
{
return $this->line;
}
/**
* @param int $line
*/
public function setLine($line)
{
$this->line = $line;
}
}

View File

@ -0,0 +1,227 @@
<?php
/**
* Html2Pdf Library - parsing Html class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Parsing;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
/**
* Class TagParser
*/
class TagParser
{
protected $level; // table level
protected $num = 0; // table number
protected $textParser;
public function __construct(TextParser $textParser)
{
$this->textParser = $textParser;
$this->level = array($this->num);
}
/**
* analyze a HTML tag
*
* @param string $code HTML code to analyze
*
* @return Node corresponding action
* @throws HtmlParsingException
*/
public function analyzeTag($code)
{
// name of the tag, opening, closure, autoclosure
$tag = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)';
if (!preg_match('/'.$tag.'/isU', $code, $match)) {
$e = new HtmlParsingException('The HTML tag ['.$code.'] provided is invalid');
$e->setInvalidTag($code);
throw $e;
}
$close = ($match[1] === '/' ? true : false);
$autoclose = preg_match('/\/>$/isU', $code);
$name = strtolower($match[2]);
// required parameters (depends on the tag name)
$defaultParams = array();
$defaultParams['style'] = '';
if ($name === 'img') {
$defaultParams['alt'] = '';
$defaultParams['src'] = '';
} elseif ($name === 'a') {
$defaultParams['href'] = '';
}
$param = array_merge($defaultParams, $this->extractTagAttributes($code));
$param['style'] = trim($param['style']);
if (strlen($param['style']) > 0 && substr($param['style'], -1) !== ';') {
$param['style'].= ';';
}
// compliance of each parameter
$color = "#000000";
$border = null;
foreach ($param as $key => $val) {
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] = (int) $val;
break;
case 'color':
if ($name === 'font') {
unset($param[$key]);
$param['style'] .= 'color: '.$val.'; ';
}
break;
}
}
// compliance of the border
if ($border !== null) {
if ($border && $border !== '0px') {
$border = 'solid '.$border.' '.$color;
} else {
$border = 'none';
}
$param['style'] .= 'border: '.$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++;
array_push($this->level, $this->num);
}
// get the level of the table containing the element
if (!isset($param['num'])) {
$param['num'] = end($this->level);
}
// for closures table: remove a level
if (in_array($name, array('ul', 'ol', 'table')) && $close) {
array_pop($this->level);
}
// prepare the parameters
if (isset($param['value'])) {
$keepSpaces = in_array($name, array('qrcode', 'barcode'));
$param['value'] = $this->textParser->prepareTxt($param['value'], !$keepSpaces);
}
if (isset($param['alt'])) {
$param['alt'] = $this->textParser->prepareTxt($param['alt']);
}
if (isset($param['title'])) {
$param['title'] = $this->textParser->prepareTxt($param['title']);
}
if (isset($param['class'])) {
$param['class'] = $this->textParser->prepareTxt($param['class']);
}
// return the new action to do
return new Node($name, $param, $close, $autoclose);
}
/**
* Extract the list of attribute => value inside an HTML tag
*
* @param string $code The full HTML tag to parse
*
* @return array
*/
public function extractTagAttributes($code)
{
$param = array();
$regexes = array(
'([a-zA-Z0-9_]+)=([^"\'\s>]+)', // read the parameters : name=value
'([a-zA-Z0-9_]+)=["]([^"]*)["]', // read the parameters : name="value"
"([a-zA-Z0-9_]+)=[']([^']*)[']" // read the parameters : name='value'
);
foreach ($regexes as $regex) {
preg_match_all('/'.$regex.'/is', $code, $match);
$amountMatch = count($match[0]);
for ($k = 0; $k < $amountMatch; $k++) {
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
}
}
return $param;
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Html2Pdf Library - parsing Html class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Parsing;
/**
* Class TextParser
*/
class TextParser
{
/**
* @var string
*/
private $encoding;
/**
* @param string $encoding
*/
public function __construct($encoding = 'UTF-8')
{
$this->encoding = $encoding;
}
/**
* prepare the text
*
* @param string $txt
* @param boolean $spaces true => replace multiple space+\t+\r+\n by a single space
* @return string txt
* @access protected
*/
public function prepareTxt($txt, $spaces = true)
{
if ($spaces) {
$txt = preg_replace('/\s+/isu', ' ', $txt);
}
$txt = str_replace('&euro;', '€', $txt);
$txt = html_entity_decode($txt, ENT_QUOTES, $this->encoding);
return $txt;
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Parsing;
/**
* Class Token
*
* Represents a token in the HTML flow
*/
class Token
{
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $data;
/**
* @var int
*/
private $line;
/**
* @param string $type
* @param string $data
* @param int $line
*/
public function __construct($type, $data, $line = -1)
{
$this->type = $type;
$this->data = $data;
$this->line = $line;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return string
*/
public function getData()
{
return $this->data;
}
/**
* @return int
*/
public function getLine()
{
return $this->line;
}
}

View File

@ -0,0 +1,287 @@
<?php
/**
* Html2Pdf Library
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
/**
* Class SvgDrawer
*/
class SvgDrawer
{
/**
* @var MyPdf
*/
private $pdf;
/**
* @var array
*/
private $properties;
/**
* @var CssConverter
*/
private $cssConverter;
/**
* SvgDrawer constructor.
*
* @param MyPdf $pdf
* @param CssConverter $cssConverter
*/
public function __construct(
MyPdf $pdf,
CssConverter $cssConverter
) {
$this->pdf = $pdf;
$this->cssConverter = $cssConverter;
}
/**
* Start Drawing
*
* @param array $properties
* @throws HtmlParsingException
*/
public function startDrawing($properties)
{
if ($this->isDrawing()) {
$e = new HtmlParsingException('We are already in a draw tag');
$e->setInvalidTag('draw');
throw $e;
}
$this->properties = $properties;
// init the translate matrix : (0,0) => (x, y)
$this->pdf->doTransform(array(1,0,0,1,$this->getProperty('x'),$this->getProperty('y')));
$this->pdf->setAlpha(1.);
}
/**
* Stop Drawing
*/
public function stopDrawing()
{
$this->properties = null;
$this->pdf->setAlpha(1.);
$this->pdf->undoTransform();
$this->pdf->clippingPathStop();
}
/**
* Are we drawing ?
*
* @return bool
*/
public function isDrawing()
{
return is_array($this->properties);
}
/**
* Get the property
*
* @param string $key
* @return mixed
*/
public function getProperty($key)
{
return $this->properties[$key];
}
/**
* prepare a transform matrix
*
* @param string $transform
* @return array
*/
public function prepareTransform($transform)
{
// it can not be empty
if (!$transform) {
return null;
}
// sections must be like scale(...)
if (!preg_match_all('/([a-z]+)\(([^\)]*)\)/isU', $transform, $match)) {
return null;
}
// prepare the list of the actions
$actions = array();
// for actions
$amountMatches = count($match[0]);
for ($k=0; $k < $amountMatches; $k++) {
// get the name of the action
$name = strtolower($match[1][$k]);
// get the parameters of the action
$values = [];
$string = trim($match[2][$k]);
if ($string !== '') {
$values = explode(',', $string);
}
foreach ($values as $key => $value) {
$value = trim($value);
if ($value === '') {
unset($values[$key]);
continue;
}
$values[$key] = $value;
}
// prepare the matrix, depending on the action
switch ($name) {
case 'scale':
if (!array_key_exists(0, $values)) {
$values[0] = 1.;
}
if (!array_key_exists(1, $values)) {
$values[1] = $values[0];
}
$values[0] = floatval($values[0]);
$values[1] = floatval($values[1]);
$actions[] = array($values[0],0.,0.,$values[1],0.,0.);
break;
case 'translate':
if (!array_key_exists(0, $values)) {
$values[0] = 0.;
}
if (!array_key_exists(1, $values)) {
$values[1] = 0.;
}
$values[0] = $this->cssConverter->convertToMM($values[0], $this->getProperty('w'));
$values[1] = $this->cssConverter->convertToMM($values[1], $this->getProperty('h'));
$actions[] = array(1.,0.,0.,1.,$values[0],$values[1]);
break;
case 'rotate':
if (!array_key_exists(0, $values)) {
$values[0] = 0.;
}
if (!array_key_exists(1, $values)) {
$values[1] = 0.;
}
if (!array_key_exists(2, $values)) {
$values[2] = 0.;
}
$values[0] = $values[0]*M_PI/180.;
$values[1] = $this->cssConverter->convertToMM($values[1], $this->getProperty('w'));
$values[2] = $this->cssConverter->convertToMM($values[2], $this->getProperty('h'));
if ($values[1] || $values[2]) {
$actions[] = array(1.,0.,0.,1.,-$values[1],-$values[2]);
}
$actions[] = array(cos($values[0]),sin($values[0]),-sin($values[0]),cos($values[0]),0.,0.);
if ($values[1] || $values[2]) {
$actions[] = array(1.,0.,0.,1.,$values[1],$values[2]);
}
break;
case 'skewx':
if (!array_key_exists(0, $values)) {
$values[0] = 0.;
}
$values[0] = $values[0]*M_PI/180.;
$actions[] = array(1.,0.,tan($values[0]),1.,0.,0.);
break;
case 'skewy':
if (!array_key_exists(0, $values)) {
$values[0] = 0.;
}
$values[0] = $values[0]*M_PI/180.;
$actions[] = array(1.,tan($values[0]),0.,1.,0.,0.);
break;
case 'matrix':
if (!array_key_exists(0, $values)) {
$values[0] = 0.;
}
if (!array_key_exists(1, $values)) {
$values[1] = 0.;
}
if (!array_key_exists(2, $values)) {
$values[2] = 0.;
}
if (!array_key_exists(3, $values)) {
$values[3] = 0.;
}
if (!array_key_exists(4, $values)) {
$values[4] = 0.;
}
if (!array_key_exists(5, $values)) {
$values[5] = 0.;
}
$values[0] = floatval($values[0]);
$values[1] = floatval($values[1]);
$values[2] = floatval($values[2]);
$values[3] = floatval($values[3]);
$values[4] = $this->cssConverter->convertToMM($values[4], $this->getProperty('w'));
$values[5] = $this->cssConverter->convertToMM($values[5], $this->getProperty('h'));
$actions[] = $values;
break;
}
}
// if there are no actions => return
if (!$actions) {
return null;
}
// get the first matrix
$m = $actions[0];
unset($actions[0]);
// foreach matrix => multiply to the last matrix
foreach ($actions as $n) {
$m = array(
$m[0]*$n[0]+$m[2]*$n[1],
$m[1]*$n[0]+$m[3]*$n[1],
$m[0]*$n[2]+$m[2]*$n[3],
$m[1]*$n[2]+$m[3]*$n[3],
$m[0]*$n[4]+$m[2]*$n[5]+$m[4],
$m[1]*$n[4]+$m[3]*$n[5]+$m[5]
);
}
// return the matrix
return $m;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag;
/**
* Abstract Default Tag
* used by all the simple tags like b, u, i, ...
*/
abstract class AbstractHtmlTag extends AbstractTag
{
/**
* Open the HTML tag
*
* @param array $properties properties of the HTML tag
*
* @return boolean
*/
public function open($properties)
{
$this->parsingCss->save();
$this->overrideStyles();
$this->parsingCss->analyse($this->getName(), $properties);
$this->parsingCss->setPosition();
$this->parsingCss->fontSet();
return true;
}
/**
* override some styles
*
* @return $this
*/
protected function overrideStyles()
{
return $this;
}
/**
* Close the HTML tag
*
* @param array $properties properties of the HTML tag
*
* @return boolean
*/
public function close($properties)
{
$this->parsingCss->load();
$this->parsingCss->fontSet();
return true;
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\SvgDrawer;
/**
* Abstract Default Tag
* used by all the svg tags
*/
abstract class AbstractSvgTag extends AbstractTag
{
/**
* @var SvgDrawer
*/
protected $svgDrawer;
/**
* AbstractSvgTag constructor.
*
* @param SvgDrawer $svgDrawer
*/
public function __construct(SvgDrawer $svgDrawer)
{
parent::__construct();
$this->svgDrawer = $svgDrawer;
}
/**
* @inheritdoc
*/
public function open($properties)
{
$this->openSvg($properties);
$this->drawSvg($properties);
$this->closeSvg();
return true;
}
/**
* @inheritdoc
*/
public function close($properties)
{
return true;
}
/**
* Open the SVG tag
*
* @param array $properties
* @throws HtmlParsingException
*/
protected function openSvg($properties)
{
if (!$this->svgDrawer->isDrawing()) {
$e = new HtmlParsingException('The asked ['.$this->getName().'] tag is not in a [DRAW] tag');
$e->setInvalidTag($this->getName());
throw $e;
}
$transform = null;
if (array_key_exists('transform', $properties)) {
$transform = $this->svgDrawer->prepareTransform($properties['transform']);
}
$this->pdf->doTransform($transform);
$this->parsingCss->save();
}
/**
* Close the SVG tag
*/
protected function closeSvg()
{
$this->pdf->undoTransform();
$this->parsingCss->load();
}
/**
* Draw the SVG tag
*
* @param array $properties
*
* @return void
*/
abstract protected function drawSvg($properties);
}

View File

@ -0,0 +1,113 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag;
use Spipu\Html2Pdf\CssConverter;
use Spipu\Html2Pdf\MyPdf;
use Spipu\Html2Pdf\Debug\DebugInterface;
use Spipu\Html2Pdf\Parsing\Css as ParsingCss;
/**
* Abstract Tag
* must be used by all the tags
*/
abstract class AbstractTag implements TagInterface
{
/**
* Css Parsing object
* @var ParsingCss
*/
protected $parsingCss;
/**
* Css Converter object
* @var CssConverter
*/
protected $cssConverter;
/**
* Pdf object
* @var MyPdf
*/
protected $pdf;
/**
* Debug object
* @var DebugInterface
*/
protected $debug;
/**
* PHP constructor.
*/
public function __construct()
{
}
/**
* Set the Parsing Css Object
*
* @param ParsingCss $parsingCss The parsing css object
*
* @return AbstractTag
*/
public function setParsingCssObject(ParsingCss $parsingCss)
{
$this->parsingCss = $parsingCss;
return $this;
}
/**
* Set the Parsing Css Object
*
* @param CssConverter $cssConverter The css converter object
*
* @return AbstractTag
*/
public function setCssConverterObject(CssConverter $cssConverter)
{
$this->cssConverter = $cssConverter;
return $this;
}
/**
* Set the Pdf Object
*
* @param MyPdf $pdf The pdf object
*
* @return TagInterface
*/
public function setPdfObject(MyPdf $pdf)
{
$this->pdf = $pdf;
return $this;
}
/**
* Set the Debug Object
*
* @param DebugInterface $debug The Debug object
*
* @return TagInterface
*/
public function setDebugObject(DebugInterface $debug)
{
$this->debug = $debug;
return $this;
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Address
*/
class Address extends I
{
/**
* @inheritdoc
*/
public function getName()
{
return 'address';
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag B
*/
class B extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'b';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['font-bold'] = true;
return $this;
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag Big
*/
class Big extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'big';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['mini-decal']-= $this->parsingCss->value['mini-size']*0.12;
$this->parsingCss->value['mini-size'] *= 1.2;
return $this;
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractTag;
/**
* Tag Bookmark
*/
class Bookmark extends AbstractTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'bookmark';
}
/**
* @inheritdoc
*/
public function open($properties)
{
$titre = isset($properties['title']) ? trim($properties['title']) : '';
$level = isset($properties['level']) ? floor($properties['level']) : 0;
if ($level < 0) {
$level = 0;
}
if ($titre) {
$this->pdf->Bookmark($titre, $level, -1);
}
return true;
}
/**
* @inheritdoc
*/
public function close($properties)
{
// there is nothing to do here
return true;
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Cite
*/
class Cite extends I
{
/**
* @inheritdoc
*/
public function getName()
{
return 'cite';
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Del
*/
class Del extends S
{
/**
* @inheritdoc
*/
public function getName()
{
return 'del';
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Em
*/
class Em extends I
{
/**
* @inheritdoc
*/
public function getName()
{
return 'em';
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Font
*/
class Font extends Span
{
/**
* @inheritdoc
*/
public function getName()
{
return 'font';
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag I
*/
class I extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'i';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['font-italic'] = true;
return $this;
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Ins
*/
class Ins extends U
{
/**
* @inheritdoc
*/
public function getName()
{
return 'ins';
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Label
*/
class Label extends Span
{
/**
* @inheritdoc
*/
public function getName()
{
return 'label';
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag S
*/
class S extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 's';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['font-linethrough'] = true;
return $this;
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Samp
*/
class Samp extends I
{
/**
* @inheritdoc
*/
public function getName()
{
return 'samp';
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag Small
*/
class Small extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'small';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['mini-decal']+= $this->parsingCss->value['mini-size']*0.05;
$this->parsingCss->value['mini-size'] *= 0.82;
return $this;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag Span
*/
class Span extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'span';
}
/**
* @inheritdoc
*/
public function close($properties)
{
$this->parsingCss->restorePosition();
return parent::close($properties);
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
/**
* Tag Strong
*/
class Strong extends B
{
/**
* @inheritdoc
*/
public function getName()
{
return 'strong';
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag Sub
*/
class Sub extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'sub';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['mini-decal']+= $this->parsingCss->value['mini-size']*0.15;
$this->parsingCss->value['mini-size'] *= 0.75;
return $this;
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag Sup
*/
class Sup extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'sup';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['mini-decal']-= $this->parsingCss->value['mini-size']*0.15;
$this->parsingCss->value['mini-size'] *= 0.75;
return $this;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Html;
use Spipu\Html2Pdf\Tag\AbstractHtmlTag;
/**
* Tag U
*/
class U extends AbstractHtmlTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'u';
}
/**
* @inheritdoc
*/
protected function overrideStyles()
{
$this->parsingCss->value['font-underline'] = true;
return $this;
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Circle
*/
class Circle extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'circle';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$style = $this->pdf->svgSetStyle($styles);
$cx = 0.;
if (isset($properties['cx'])) {
$cx = $this->cssConverter->convertToMM($properties['cx'], $this->svgDrawer->getProperty('w'));
}
$cy = 0.;
if (isset($properties['cy'])) {
$cy = $this->cssConverter->convertToMM($properties['cy'], $this->svgDrawer->getProperty('h'));
}
$r = 0.;
if (isset($properties['r'])) {
$r = $this->cssConverter->convertToMM($properties['r'], $this->svgDrawer->getProperty('w'));
}
$this->pdf->svgEllipse($cx, $cy, $r, $r, $style);
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Ellipse
*/
class Ellipse extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'ellipse';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$style = $this->pdf->svgSetStyle($styles);
$cx = 0.;
if (isset($properties['cx'])) {
$cx = $this->cssConverter->convertToMM($properties['cx'], $this->svgDrawer->getProperty('w'));
}
$cy = 0.;
if (isset($properties['cy'])) {
$cy = $this->cssConverter->convertToMM($properties['cy'], $this->svgDrawer->getProperty('h'));
}
$rx = 0.;
if (isset($properties['rx'])) {
$rx = $this->cssConverter->convertToMM($properties['rx'], $this->svgDrawer->getProperty('w'));
}
$ry = 0.;
if (isset($properties['ry'])) {
$ry = $this->cssConverter->convertToMM($properties['ry'], $this->svgDrawer->getProperty('h'));
}
$this->pdf->svgEllipse($cx, $cy, $rx, $ry, $style);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag G
*/
class G extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'g';
}
/**
* @inheritdoc
*/
public function open($properties)
{
$this->openSvg($properties);
$this->drawSvg($properties);
return true;
}
/**
* @inheritdoc
*/
public function close($properties)
{
$this->closeSvg();
return true;
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$this->pdf->svgSetStyle($styles);
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Line
*/
class Line extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'line';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$styles['fill'] = null;
$this->pdf->svgSetStyle($styles);
$x1 = 0.;
if (isset($properties['x1'])) {
$x1 = $this->cssConverter->convertToMM($properties['x1'], $this->svgDrawer->getProperty('w'));
}
$y1 = 0.;
if (isset($properties['y1'])) {
$y1 = $this->cssConverter->convertToMM($properties['y1'], $this->svgDrawer->getProperty('h'));
}
$x2 = 0.;
if (isset($properties['x2'])) {
$x2 = $this->cssConverter->convertToMM($properties['x2'], $this->svgDrawer->getProperty('w'));
}
$y2 = 0.;
if (isset($properties['y2'])) {
$y2 = $this->cssConverter->convertToMM($properties['y2'], $this->svgDrawer->getProperty('h'));
}
$this->pdf->svgLine($x1, $y1, $x2, $y2);
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Path
*/
class Path extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'path';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$style = $this->pdf->svgSetStyle($styles);
$path = isset($properties['d']) ? $properties['d'] : null;
if ($path) {
// prepare the path
$path = str_replace(',', ' ', $path);
$path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path);
$path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path);
$path = preg_replace('/[\s]+/', ' ', trim($path));
$path = preg_replace('/ ([a-z]{2})/', '$1', $path);
$path = preg_replace('/Z([a-zA-Z])/', 'Z $1', $path);
$path = explode(' ', $path);
foreach ($path as $k => $v) {
$path[$k] = trim($v);
if ($path[$k] === '') {
unset($path[$k]);
}
}
$path = array_values($path);
$amountPath = count($path);
// read each actions in the path
$actions = array();
$lastAction = null; // last action found
for ($k=0; $k<$amountPath; true) {
// for this actions, we can not have multi coordinate
if (in_array($lastAction, array('z', 'Z'))) {
$lastAction = null;
}
// read the new action (forcing if no action before)
if (preg_match('/^[a-z]+$/i', $path[$k]) || $lastAction === null) {
$lastAction = $path[$k];
$k++;
}
// current action
$action = array();
$action[] = $lastAction;
switch ($lastAction) {
case 'C':
case 'c':
// x1 y1 x2 y2 x y
$action[] = $this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+1], $this->svgDrawer->getProperty('h'));
$action[] = $this->cssConverter->convertToMM($path[$k+2], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+3], $this->svgDrawer->getProperty('h'));
$action[] = $this->cssConverter->convertToMM($path[$k+4], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+5], $this->svgDrawer->getProperty('h'));
$k+= 6;
break;
case 'Q':
case 'S':
case 'q':
case 's':
// x2 y2 x y
$action[] = $this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+1], $this->svgDrawer->getProperty('h'));
$action[] = $this->cssConverter->convertToMM($path[$k+2], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+3], $this->svgDrawer->getProperty('h'));
$k+= 4;
break;
case 'A':
case 'a':
// rx ry (angle de deviation de l'axe X) (large-arc-flag) (sweep-flag) x y
$action[] = $this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+1], $this->svgDrawer->getProperty('h'));
$action[] = 1.*$path[$k+2];
$action[] = ($path[$k+3] === '1') ? 1 : 0;
$action[] = ($path[$k+4] === '1') ? 1 : 0;
$action[] = $this->cssConverter->convertToMM($path[$k+5], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+6], $this->svgDrawer->getProperty('h'));
$k+= 7;
break;
case 'M':
case 'L':
case 'T':
case 'm':
case 'l':
case 't':
// x y
$action[] = $this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w'));
$action[] = $this->cssConverter->convertToMM($path[$k+1], $this->svgDrawer->getProperty('h'));
$k+= 2;
break;
case 'H':
case 'h':
// x
$action[] = $this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w'));
$k+= 1;
break;
case 'V':
case 'v':
// y
$action[] = $this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('h'));
$k+= 1;
break;
case 'z':
case 'Z':
break;
default:
$k+= 1;
break;
}
// add the action
$actions[] = $action;
}
// drawing
$this->pdf->svgPolygone($actions, $style);
}
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Polygon
*/
class Polygon extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'polygon';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$style = $this->pdf->svgSetStyle($styles);
$path = (isset($properties['points']) ? $properties['points'] : null);
if ($path) {
$path = str_replace(',', ' ', $path);
$path = preg_replace('/[\s]+/', ' ', trim($path));
// prepare the path
$path = explode(' ', $path);
foreach ($path as $k => $v) {
$path[$k] = trim($v);
if ($path[$k] === '') {
unset($path[$k]);
}
}
$path = array_values($path);
$amountPath = count($path);
$actions = array();
for ($k=0; $k<$amountPath; $k+=2) {
$actions[] = array(
($k ? 'L' : 'M') ,
$this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w')),
$this->cssConverter->convertToMM($path[$k+1], $this->svgDrawer->getProperty('h'))
);
}
$actions[] = array('z');
// drawing
$this->pdf->svgPolygone($actions, $style);
}
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Polyline
*/
class Polyline extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'polyline';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$style = $this->pdf->svgSetStyle($styles);
$path = isset($properties['points']) ? $properties['points'] : null;
if ($path) {
$path = str_replace(',', ' ', $path);
$path = preg_replace('/[\s]+/', ' ', trim($path));
// prepare the path
$path = explode(' ', $path);
foreach ($path as $k => $v) {
$path[$k] = trim($v);
if ($path[$k] === '') {
unset($path[$k]);
}
}
$path = array_values($path);
$amountPath = count($path);
$actions = array();
for ($k=0; $k<$amountPath; $k+=2) {
$actions[] = array(
($k ? 'L' : 'M') ,
$this->cssConverter->convertToMM($path[$k+0], $this->svgDrawer->getProperty('w')),
$this->cssConverter->convertToMM($path[$k+1], $this->svgDrawer->getProperty('h'))
);
}
// drawing
$this->pdf->svgPolygone($actions, $style);
}
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Html2Pdf Library - Tag class
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag\Svg;
use Spipu\Html2Pdf\Tag\AbstractSvgTag;
/**
* Tag Rect
*/
class Rect extends AbstractSvgTag
{
/**
* @inheritdoc
*/
public function getName()
{
return 'rect';
}
/**
* @inheritdoc
*/
protected function drawSvg($properties)
{
$styles = $this->parsingCss->getSvgStyle($this->getName(), $properties);
$style = $this->pdf->svgSetStyle($styles);
$x = 0.;
if (isset($properties['x'])) {
$x = $this->cssConverter->convertToMM($properties['x'], $this->svgDrawer->getProperty('w'));
}
$y = 0.;
if (isset($properties['y'])) {
$y = $this->cssConverter->convertToMM($properties['y'], $this->svgDrawer->getProperty('h'));
}
$w = 0.;
if (isset($properties['w'])) {
$w = $this->cssConverter->convertToMM($properties['w'], $this->svgDrawer->getProperty('w'));
}
$h = 0.;
if (isset($properties['h'])) {
$h = $this->cssConverter->convertToMM($properties['h'], $this->svgDrawer->getProperty('h'));
}
$this->pdf->svgRect($x, $y, $w, $h, $style);
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Html2Pdf Library - TagInterface interface
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tag;
use Spipu\Html2Pdf\CssConverter;
use Spipu\Html2Pdf\MyPdf;
use Spipu\Html2Pdf\Debug\DebugInterface;
use Spipu\Html2Pdf\Parsing\Css as ParsingCss;
interface TagInterface
{
/**
* Set the Parsing Css Object
*
* @param ParsingCss $parsingCss The parsing css object
*
* @return TagInterface
*/
public function setParsingCssObject(ParsingCss $parsingCss);
/**
* Set the Parsing Css Object
*
* @param CssConverter $cssConverter The css converter object
*
* @return TagInterface
*/
public function setCssConverterObject(CssConverter $cssConverter);
/**
* Set the Pdf Object
*
* @param MyPdf $pdf The pdf object
*
* @return TagInterface
*/
public function setPdfObject(MyPdf $pdf);
/**
* Set the Debug Object
*
* @param DebugInterface $debug The Debug object
*
* @return TagInterface
*/
public function setDebugObject(DebugInterface $debug);
/**
* get the name of the tag
*
* @return string
*/
public function getName();
/**
* Open the HTML tag
*
* @param array $properties properties of the HTML tag
*
* @return boolean
*/
public function open($properties);
/**
* Close the HTML tag
*
* @param array $properties properties of the HTML tag
*
* @return boolean
*/
public function close($properties);
}

View File

@ -0,0 +1,44 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Html2Pdf;
/**
* Class Html2PdfTest
*/
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Html2Pdf
*/
private $html2pdf;
/**
* Executed before each test
*/
protected function setUp()
{
$this->html2pdf = new Html2Pdf('P', 'A4', 'fr', true, 'UTF-8', [0, 0, 0, 0]);
$this->html2pdf->pdf->SetTitle('PhpUnit Test');
}
/**
* Executed after each test
*/
protected function tearDown()
{
$this->html2pdf->clean();
$this->html2pdf = null;
}
/**
* Get the object to test
*
* @return Html2Pdf
*/
protected function getObject()
{
return $this->html2pdf;
}
}

View File

@ -0,0 +1,117 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\CssConverter;
/**
* Class CssConverterTest
*/
class CssConverterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var CssConverter
*/
private $cssConverter;
public function setUp()
{
$this->cssConverter = new CssConverter();
}
/**
* @param string $css
* @param string $old
* @param array $expected
*
* @dataProvider convertToMMProvider
*/
public function testConvertToMM($css, $old, $expected)
{
$result = $this->cssConverter->convertToMM($css, $old);
$this->assertEquals($expected, $result);
}
public function convertToMMProvider()
{
return array(
array('100mm', null, 100),
array('100px', null, 25.4 / 96. * 100),
array('100', null, 25.4 / 96. * 100),
array('100pt', null, 25.4 / 72. * 100),
array('100in', null, 25.4 * 100),
array('10%', 100, 10),
array('100cm', null, null),
);
}
/**
* @param string $css
* @param array $expected
*
* @dataProvider convertToRadiusProvider
*/
public function testConvertToRadius($css, $expected)
{
$result = $this->cssConverter->convertToRadius($css);
$this->assertEquals(count($expected), count($result));
for ($i = 0; $i < count($result); $i++) {
$this->assertEquals($expected[$i], $result[$i]);
}
}
public function convertToRadiusProvider()
{
return array(
array('100mm', array(100)),
array('100mm 10mm', array(100, 10)),
array('100mm 10mm ', array(100, 10)),
array('100mm 10cm 10mm', array(100, 10)),
array('1mm 2mm 3mm 4mm', array(1, 2, 3, 4)),
);
}
/**
* @param string $css
* @param boolean $expectedRes
* @param array $expectedColor
*
* @dataProvider convertToColorProvider
*/
public function testConvertToColor($css, $expectedRes, $expectedColor)
{
$res = true;
$resultColor = $this->cssConverter->convertToColor($css, $res);
$this->assertEquals($expectedRes, $res);
$this->assertEquals(count($expectedColor), count($resultColor));
for ($i = 0; $i < count($resultColor); $i++) {
if (is_null($expectedColor[$i])) {
$this->assertNull($resultColor[$i]);
} else {
$this->assertEquals($expectedColor[$i], $resultColor[$i]);
}
}
}
public function convertToColorProvider()
{
return array(
array('transparent', true, array(null, null, null)),
array('aliceblue', true, array( 240, 248, 255)),
array('#F0A050', true, array( 240, 160, 80)),
array('#FA5', true, array( 255, 170, 85)),
array('rgb( 50, 100, 150)', true, array( 50, 100, 150)),
array('rgb( 10%, 20%, 30%)', true, array(25.5, 51, 76.5)),
array('rgb( 0.2, 0.4, 0.6)', true, array( 51, 102, 153)),
array('cmyk(255, 255, 255, 255)', true, array( 100, 100, 100, 100)),
array('cmyk(10%, 20%, 30%, 40%)', true, array( 10, 20, 30, 40)),
array('cmyk(0.2, 0.4, 0.6, 0.8)', true, array( 20, 40, 60, 80)),
array('blakc', false, array( 0, 0, 0)),
);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Debug;
use Spipu\Html2Pdf\Debug\Debug;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class DebugTest
*/
class DebugTest extends AbstractTest
{
/**
* test Debug Mode, Automatic
*
* @return void
*/
public function testAutomatic()
{
$html = '<p>First Tag</p>';
$html.= '<div>Second Tag</div>';
$html.= '<b>Third Tag</b>';
ob_start();
$object = $this->getObject();
$object->setModeDebug();
$object->writeHTML($html);
$pdfResult = $object->output('test.pdf', 'S');
$debugResult = ob_get_clean();
$this->assertSame('', $pdfResult);
$this->assertNotEmpty($debugResult);
}
/**
* test Debug Mode, manual
*
* @return void
*/
public function testManual()
{
$html = '<p>First Tag</p>';
$html.= '<div>Second Tag</div>';
$html.= '<b>Third Tag</b>';
// Prepare debug object, without html output
$debug = new Debug(false);
ob_start();
$object = $this->getObject();
$object->setModeDebug($debug);
$object->writeHTML($html);
$pdfResult = $object->output('test.pdf', 'S');
$debugResult = ob_get_clean();
$this->assertSame('', $pdfResult);
$this->assertNotEmpty($debugResult);
}
}

View File

@ -0,0 +1,334 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests;
/**
* Class ExamplesTest
*/
class ExamplesTest extends \PHPUnit_Framework_TestCase
{
/**
* Launch a example
*
* @param string $example code of the example
*
* @return void
* @throws \Exception
*/
protected function launchExample($example)
{
$filename = dirname(dirname(dirname(__FILE__))).'/examples/'.$example.'.php';
if (!is_file($filename)) {
throw new \Exception('The filename of the example ['.$example.'] does not exist!');
}
$folder = dirname($filename);
// get the content of the file
$content = file_get_contents($filename);
// keep only the example
$parts = explode('try {', $content);
$parts = explode('} catch', $parts[1]);
$content = $parts[0];
// replace the good path
$content = str_replace('dirname(__FILE__)', "'$folder'", $content);
// add the class to use
$content = 'use Spipu\Html2Pdf\Html2Pdf; '.$content;
// get the output
$regexp = '/\$html2pdf->output\(([^\)]*)\);/';
$replace = 'return $html2pdf->output(\'test.pdf\', \'S\');';
$content = preg_replace($regexp, $replace, $content);
// execute
$currentDir = getcwd();
chdir($folder);
$result = eval($content);
chdir($currentDir);
// test
$this->assertNotEmpty($result);
}
/**
* test: about
*
* @return void
*/
public function testAbout()
{
$this->launchExample('about');
}
/**
* test: bookmark
*
* @return void
*/
public function testBookmark()
{
$this->launchExample('bookmark');
}
/**
* test: bookmark
*
* @return void
*/
public function testBalloon()
{
$this->launchExample('balloon');
}
/**
* test: example01
*
* @return void
*/
public function testExample01()
{
$this->launchExample('example01');
}
/**
* test: example02
*
* @return void
*/
public function testExample02()
{
$this->launchExample('example02');
}
/**
* test: example03
*
* @return void
*/
public function testExample03()
{
$this->launchExample('example03');
}
/**
* test: example04
*
* @return void
*/
public function testExample04()
{
$this->launchExample('example04');
}
/**
* test: example05
*
* @return void
*/
public function testExample05()
{
$this->launchExample('example05');
}
/**
* test: example06
*
* @return void
*/
public function testExample06()
{
$this->launchExample('example06');
}
/**
* test: example07
*
* @return void
*/
public function testExample07()
{
$this->launchExample('example07');
}
/**
* test: example08
*
* @return void
*/
public function testExample08()
{
$this->launchExample('example08');
}
/**
* test: example10
*
* @return void
*/
public function testExample10()
{
$this->launchExample('example10');
}
/**
* test: example11
*
* @return void
*/
public function testExample11()
{
$this->launchExample('example11');
}
/**
* test: example12
*
* @return void
*/
public function testExample12()
{
$this->launchExample('example12');
}
/**
* test: example13
*
* @return void
*/
public function testExample13()
{
$this->launchExample('example13');
}
/**
* test: example14
*
* @return void
*/
public function testExample14()
{
$this->launchExample('example14');
}
/**
* test: example15
*
* @return void
*/
public function testExample15()
{
$this->launchExample('example15');
}
/**
* test: forms
*
* @return void
*/
public function testForms()
{
$this->launchExample('forms');
}
/**
* test: groups
*
* @return void
*/
public function testGroups()
{
$this->launchExample('groups');
}
/**
* test: qrcode
*
* @return void
*/
public function testQrcode()
{
$this->launchExample('qrcode');
}
/**
* test: radius
*
* @return void
*/
public function testRadius()
{
$this->launchExample('radius');
}
/**
* test: regle
*
* @return void
*/
public function testMeasure()
{
$this->launchExample('measure');
}
/**
* test: svg
*
* @return void
*/
public function testSvg()
{
$this->launchExample('svg');
}
/**
* test: svg_tiger
*
* @return void
*/
public function testSvgTiger()
{
$this->launchExample('svg_tiger');
}
/**
* test: svg_tree
*
* @return void
*/
public function testSvgTree()
{
$this->launchExample('svg_tree');
}
/**
* test: ticket
*
* @return void
*/
public function testTicket()
{
$this->launchExample('ticket');
}
/**
* test: utf8
*
* @return void
*/
public function testUtf8()
{
$this->launchExample('utf8');
}
}

View File

@ -0,0 +1,116 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Exception;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\HtmlParsingException;
use Spipu\Html2Pdf\Exception\ImageException;
use Spipu\Html2Pdf\Exception\LongSentenceException;
/**
* Class ExceptionFormaterTest
*/
class ExceptionFormatterTest extends \PHPUnit_Framework_TestCase
{
/**
* Test the formatter / generic exception
*/
public function testGeneric()
{
$exception = new Html2PdfException('My Message');
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.Html2PdfException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
}
}
/**
* Test the formatter / parsing exception
*/
public function testParsing()
{
$exception = new HtmlParsingException('My Message');
$exception->setInvalidTag('my_tag');
$exception->setHtmlLine(42);
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.HtmlParsingException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
$this->assertContains('my_tag', $message);
$this->assertContains('42', $message);
}
}
/**
* Test the formatter / image exception
*/
public function testImage()
{
$exception = new ImageException('My Message');
$exception->setImage('my_image.png');
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.ImageException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
$this->assertContains('my_image.png', $message);
}
}
/**
* Test the formatter / long sentence exception
*/
public function testLongSentence()
{
$exception = new LongSentenceException('My Message');
$exception->setSentence('my sentence');
$exception->setLength(142);
$exception->setWidthBox(242);
$formatter = new ExceptionFormatter($exception);
$messages = [
$formatter->getMessage(),
$formatter->getHtmlMessage()
];
foreach ($messages as $message) {
$this->assertContains('Html2Pdf Error ['.LongSentenceException::ERROR_CODE.']', $message);
$this->assertContains('My Message', $message);
$this->assertContains('my sentence', $message);
$this->assertContains('142', $message);
$this->assertContains('242', $message);
}
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Exception;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class DebugTest
*/
class LongSentenceExceptionTest extends AbstractTest
{
/**
* test LongSentence Exception
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\LongSentenceException
*/
public function testBug()
{
$sentence = 'This is a sentence.';
$bigSentence = $sentence;
for ($k=0; $k<110; $k++) {
$bigSentence.= ' '.$sentence;
}
$html = '<page backleft="0" backright="200mm"style="font-size: 1mm">'.$bigSentence.'</page>';
$object = $this->getObject();
$object->setSentenceMaxLines(100);
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Phake;
use Spipu\Html2Pdf\Html2Pdf;
/**
* Class Html2PdfTest
*/
class Html2PdfTest extends AbstractTest
{
public function testExtensionTag()
{
$tag = Phake::mock('Spipu\Html2Pdf\Tag\TagInterface');
Phake::when($tag)->getName()->thenReturn('test_tag');
$extension = Phake::mock('Spipu\Html2Pdf\Extension\ExtensionInterface');
Phake::when($extension)->getName()->thenReturn('test');
Phake::when($extension)->getTags()->thenReturn(array($tag));
$object = $this->getObject();
$object->addExtension($extension);
$object->writeHTML('<div><test_tag>Hello</test_tag></div>');
Phake::verify($tag, Phake::times(4))->open;
Phake::verify($tag, Phake::times(2))->close;
}
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Exception\ImageException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class BackgroundErrorTest
*/
class BackgroundErrorTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\ImageException
*/
public function testCase()
{
$image = '/res/wrong.png';
try {
$object = $this->getObject();
$object->writeHTML('<div style="background-image: url('.$image.')">Hello World</div>');
$object->output('test.pdf', 'S');
} catch (ImageException $e) {
$this->assertSame($image, $e->getImage());
throw $e;
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class BackgroundOkTest
*/
class BackgroundOkTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<div style="background-image: url('.dirname(__FILE__).'/res/logo.png)">Hello World</div>');
$result = $object->output('test.pdf', 'S');
$this->assertContains('PhpUnit Test', $result);
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\ImageException;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class SrcErrorTest
*/
class SrcErrorTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\ImageException
*/
public function testCase()
{
$image = '/res/wrong.png';
try {
$object = $this->getObject();
$object->writeHTML('Hello World <img src="'.$image.'" />');
$object->output('test.pdf', 'S');
} catch (ImageException $e) {
$this->assertSame($image, $e->getImage());
throw $e;
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Image;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class SrcOkTest
*/
class SrcOkTest extends AbstractTest
{
/**
* test: The image src is unknown
*
* @return void
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('Hello World <img src="'.dirname(__FILE__).'/res/logo.png" />');
$result = $object->output('test.pdf', 'S');
$this->assertContains('PhpUnit Test', $result);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,73 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests;
use Spipu\Html2Pdf\Locale;
use Spipu\Html2Pdf\Exception\LocaleException;
/**
* Class LocaleTest
*/
class LocaleTest extends \PHPUnit_Framework_TestCase
{
/**
* test bad code
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\LocaleException
*/
public function testBadCode()
{
Locale::clean();
try {
Locale::load('$aa');
} catch (LocaleException $e) {
$this->assertSame('$aa', $e->getLocalCode());
throw $e;
}
}
/**
* test unknown code
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\LocaleException
*/
public function testUnknownCode()
{
Locale::clean();
try {
Locale::load('aa');
} catch (LocaleException $e) {
$this->assertSame('aa', $e->getLocalCode());
throw $e;
}
}
/**
* test good code
*
* @return void
*/
public function testGoodCode()
{
Locale::clean();
Locale::load('en');
$this->assertSame('Page [[page_cu]]/[[page_nb]]', Locale::get('pdf04'));
$this->assertSame('bad_return', Locale::get('bad_code', 'bad_return'));
Locale::clean();
$this->assertSame('bad_return', Locale::get('pdf04', 'bad_return'));
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Output;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class FileNameOkTest
*/
class FileNameOkTest extends AbstractTest
{
/**
* test: the file extension must be PDF - OK
*
* @return void
*/
public function testOk()
{
$object = $this->getObject();
$object->writeHTML('Hello World');
ob_start();
$object->output('test.pdf');
$result = ob_get_clean();
$this->assertContains('PhpUnit Test', $result);
}
/**
* test: the file extension is ignored if output string
*
* @return void
*/
public function testIgnore()
{
$object = $this->getObject();
$object->writeHTML('Hello World');
$result = $object->output('test.bad', 'S');
$this->assertContains('PhpUnit Test', $result);
}
/**
* test: the file extension must be PDF - Error
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\Html2PdfException
*/
public function testError()
{
$object = $this->getObject();
$object->writeHTML('<p>Hello World</p>');
$object->output('test.bad');
}
}

View File

@ -0,0 +1,72 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Parsing\HtmlLexer;
/**
* Class HtmlLexerTest
*/
class HtmlLexerTest extends \PHPUnit_Framework_TestCase
{
/**
* 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());
}
}
/**
* provider: tokenize
*
* @return array
*/
public function tokenizeProvider()
{
return array(
array(
'<p>test</p>',
array(
array('code', '<p>', 1),
array('txt', 'test', -1),
array('code', '</p>', 1),
)
),
array(
"<a><!-- comment -->\n<b><c>test",
array(
array('code', '<a>', 1),
array('txt', "\n", -1),
array('code', '<b>', 2),
array('code', '<c>', 2),
array('txt', "test", -1),
)
)
);
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Parsing\Html;
/**
* Class HtmlTest
*/
class HtmlTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Html
*/
private $object;
protected function setUp()
{
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
->disableOriginalConstructor()
->setMethods(['prepareTxt'])
->getMock();
$textParser
->expects($this->any())
->method('prepareTxt')
->will($this->returnCallback([$this, 'mockPrepareTxt']));
$this->object = new Html($textParser);
}
/**
* mock of prepareTxt method
*
* @param $txt
* @param bool $spaces
* @return mixed
*/
public function mockPrepareTxt($txt, $spaces = true)
{
return $txt;
}
/**
* Test the prepareHtml method
*/
public function testPrepareHtml()
{
$result = $this->object->prepareHtml('Hello [[date_y]]-[[date_m]]-[[date_d]] World');
$this->assertSame('Hello '.date('Y-m-d').' World', $result);
$result = $this->object->prepareHtml('Hello [[date_h]]:[[date_i]]:[[date_s]] World');
$this->assertSame('Hello '.date('H:i:s').' World', $result);
$html = '
<html>
<head>
<style type="text">.my-class { color: red; }</style>
<link type="text/css" href="my-style.css"/>
</head>
<body class="my-class"><p>Hello World</p></body>
</html>';
$expected='<style type="text">.my-class { color: red; }</style>'.
'<link type="text/css" href="my-style.css"/>'.
'<page class="my-class"><p>Hello World</p></page>';
$result = $this->object->prepareHtml($html);
$this->assertSame($expected, $result);
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class ParsingTest
*/
class ParsingTest extends AbstractTest
{
/**
* test: The tag is unknown
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testUnknownTag()
{
$object = $this->getObject();
$object->writeHTML('<bad_tag>Hello World</bad_tag>');
$object->output('test.pdf', 'S');
}
/**
* test: Too many tag closures found
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testTooManyClosuresFound()
{
$object = $this->getObject();
$object->writeHTML('<i><u>Hello</u></i></b>');
$object->output('test.pdf', 'S');
}
/**
* test: Tags are closed in a wrong order
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testWrongClosedOrder()
{
$object = $this->getObject();
$object->writeHTML('<b><u><i>Hello</u></i></b>');
$object->output('test.pdf', 'S');
}
/**
* test: The following tag has not been closed
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testNotClosed()
{
$object = $this->getObject();
$object->writeHTML('<b><i>Hello</i>');
$object->output('test.pdf', 'S');
}
/**
* test: The following tags have not been closed
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testNotClosedMore()
{
$object = $this->getObject();
$object->writeHTML('<b><u><i>Hello</i>');
$object->output('test.pdf', 'S');
}
/**
* test: The HTML tag code provided is invalid
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testInvalidCode()
{
$object = $this->getObject();
$object->writeHTML('<az1-r_h>Hello</az1-r_h>');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,223 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Parsing\Node;
use Spipu\Html2Pdf\Parsing\TagParser;
/**
* Class TagParserTest
*/
class TagParserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TagParser
*/
private $parser;
protected function setUp()
{
$textParser = $this->getMockBuilder('Spipu\Html2Pdf\Parsing\TextParser')
->disableOriginalConstructor()
->setMethods(['prepareTxt'])
->getMock();
$textParser
->expects($this->any())
->method('prepareTxt')
->will($this->returnCallback([$this, 'mockPrepareTxt']));
$this->parser = new TagParser($textParser);
}
/**
* mock of prepareTxt method
*
* @param $txt
* @param bool $spaces
* @return mixed
*/
public function mockPrepareTxt($txt, $spaces = true)
{
return $txt;
}
/**
* @param string $code
* @param array $expected
*
* @dataProvider tagAttributesProvider
*/
public function testExtractTagAttributes($code, $expected)
{
$result = $this->parser->extractTagAttributes($code);
$this->assertEquals($expected, $result);
}
/**
* @return array
*/
public function tagAttributesProvider()
{
return array(
array('attr=value', array('attr' => 'value')),
array('attr="value"', array('attr' => 'value')),
array('attr=\'value\'', array('attr' => 'value')),
array('attr="value with spaces"', array('attr' => 'value with spaces')),
array('attr="value with \'quotes"', array('attr' => 'value with \'quotes')),
array('my attr="value"', array('attr' => 'value')),
array('attr1=val1 attr2="value2"', array('attr1' => 'val1', 'attr2' => 'value2')),
);
}
/**
* Test if a bad tag is detected
*
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testAnalyzeTagBadTag()
{
$this->parser->analyzeTag('test');
}
/**
* Test basic open, close, autoclose tags
*/
public function testBasicTags()
{
$result = $this->parser->analyzeTag('<my_tag/>');
$this->assertTrue($result instanceof Node);
$this->assertSame('my_tag', $result->getName());
$this->assertSame(true, $result->isAutoClose());
$this->assertSame(false, $result->isClose());
$result->setLine(10);
$this->assertSame(10, $result->getLine());
$result->setParam('attr', 'value');
$this->assertSame('value', $result->getParam('attr'));
$result = $this->parser->analyzeTag('<my_tag>');
$this->assertSame('my_tag', $result->getName());
$this->assertSame(false, $result->isAutoClose());
$this->assertSame(false, $result->isClose());
$this->assertSame(['style' => [], 'num' => 0], $result->getParams());
$this->assertSame('default', $result->getParam('attr', 'default'));
$result = $this->parser->analyzeTag('</my_tag>');
$this->assertSame('my_tag', $result->getName());
$this->assertSame(false, $result->isAutoClose());
$this->assertSame(true, $result->isClose());
}
/**
* Test styles
*/
public function testAnalyzeAttributes()
{
$result = $this->parser->analyzeTag('<img src="my_src" alt="my alt"/>');
$this->assertSame('my_src', $result->getParam('src'));
$this->assertSame('my alt', $result->getParam('alt'));
$result = $this->parser->analyzeTag('<a href="my_src" title="my title"/>');
$this->assertSame('my_src', $result->getParam('href'));
$this->assertSame('my title', $result->getParam('title'));
$result = $this->parser->analyzeTag('<input type="text" value="my value" class="my_class" />');
$this->assertSame('text', $result->getParam('type'));
$this->assertSame('my value', $result->getParam('value'));
$this->assertSame('my_class', $result->getParam('class'));
$result = $this->parser->analyzeTag('<my_tag width="10" height="20" align="center" valign="bottom" bgcolor="red">');
$this->assertSame('10px', $result->getStyle('width'));
$this->assertSame('20px', $result->getStyle('height'));
$this->assertSame('center', $result->getStyle('text-align'));
$this->assertSame('bottom', $result->getStyle('vertical-align'));
$this->assertSame('red', $result->getStyle('background'));
$result = $this->parser->analyzeTag('<img align="right">');
$this->assertSame('right', $result->getStyle('float'));
$result = $this->parser->analyzeTag('<table cellpadding="1" cellspacing="2">');
$this->assertSame('1px', $result->getParam('cellpadding'));
$this->assertSame('2px', $result->getParam('cellspacing'));
$result = $this->parser->analyzeTag('<td rowspan="0" colspan="2px">');
$this->assertSame(1, $result->getParam('rowspan'));
$this->assertSame(2, $result->getParam('colspan'));
$result = $this->parser->analyzeTag('<my_tag color="red">');
$this->assertSame('red', $result->getParam('color'));
$this->assertSame(null, $result->getStyle('color'));
$result = $this->parser->analyzeTag('<font color="red">');
$this->assertSame(null, $result->getParam('color'));
$this->assertSame('red', $result->getStyle('color'));
}
/**
* Test borders
*/
public function testBorders()
{
$result = $this->parser->analyzeTag('<div border="1" bordercolor="red" />');
$this->assertSame('div', $result->getName());
$this->assertSame('solid 1px red', $result->getParam('border'));
$this->assertSame('solid 1px red', $result->getStyle('border'));
$result = $this->parser->analyzeTag('<div border="0" bordercolor="red" />');
$this->assertSame('div', $result->getName());
$this->assertSame('none', $result->getParam('border'));
$this->assertSame('none', $result->getStyle('border'));
}
/**
* Test levels
*/
public function testLevels()
{
$result = $this->parser->analyzeTag('<basic_tag>');
$this->assertSame(0, $result->getParam('num'));
$result = $this->parser->analyzeTag('<table>');
$this->assertSame(1, $result->getParam('num'));
$result = $this->parser->analyzeTag('<ol>');
$this->assertSame(2, $result->getParam('num'));
$result = $this->parser->analyzeTag('<ul>');
$this->assertSame(3, $result->getParam('num'));
$result = $this->parser->analyzeTag('</ul>');
$this->assertSame('ul', $result->getName());
$this->assertSame(3, $result->getParam('num'));
$result = $this->parser->analyzeTag('</ol>');
$this->assertSame(2, $result->getParam('num'));
$result = $this->parser->analyzeTag('</table>');
$this->assertSame(1, $result->getParam('num'));
$result = $this->parser->analyzeTag('<basic_tag>');
$this->assertSame(0, $result->getParam('num'));
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Parsing\TextParser;
/**
* Class TextParserTest
*/
class TextParserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TextParser
*/
private $parser;
protected function setUp()
{
$this->parser = new TextParser();
}
/**
* Test if it works
*/
public function testOk()
{
$result = $this->parser->prepareTxt('hello world', false);
$this->assertSame('hello world', $result);
$result = $this->parser->prepareTxt('hello world', true);
$this->assertSame('hello world', $result);
$result = $this->parser->prepareTxt('hello 10&euro; world');
$this->assertSame('hello 10€ world', $result);
$result = $this->parser->prepareTxt('hello &lt; world');
$this->assertSame('hello < world', $result);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Parsing;
use Spipu\Html2Pdf\Parsing\Token;
/**
* Class TokenTest
*/
class TokenTest extends \PHPUnit_Framework_TestCase
{
/**
* Test if it works
*/
public function testOk()
{
$token = new Token('hello', 'world', 45);
$this->assertSame('hello', $token->getType());
$this->assertSame('world', $token->getData());
$this->assertSame(45, $token->getLine());
}
}

View File

@ -0,0 +1,296 @@
<?php
namespace Spipu\Html2Pdf\Tests;
use Phake;
use Spipu\Html2Pdf\CssConverter;
use Spipu\Html2Pdf\SvgDrawer;
/**
* Class Html2PdfTest
*/
class SvgDrawerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SvgDrawer
*/
private $svgDrawer;
public function setUp()
{
$myPdf = Phake::mock('Spipu\Html2Pdf\MyPdf');
$cssConverter = new CssConverter();
$this->svgDrawer = new SvgDrawer($myPdf, $cssConverter);
}
/**
* Test IsDrawing Exception
*
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testIsDrawingException()
{
$properties = [
'x' => 0,
'y' => 0,
'w' => '100mm',
'h' => '100mm',
];
$this->svgDrawer->startDrawing($properties);
$this->svgDrawer->startDrawing($properties);
}
/**
* Test IsDrawing
*/
public function testIsDrawingOk()
{
$properties = [
'x' => 0,
'y' => 0,
'w' => 100,
'h' => 100,
];
$this->assertFalse($this->svgDrawer->isDrawing());
$this->svgDrawer->startDrawing($properties);
$this->assertTrue($this->svgDrawer->isDrawing());
$this->svgDrawer->stopDrawing();
$this->assertFalse($this->svgDrawer->isDrawing());
}
/**
* Test properties
*/
public function testProperties()
{
$properties = [
'x' => 1,
'y' => 2,
'w' => 3,
'h' => 4,
];
$this->svgDrawer->startDrawing($properties);
$this->assertSame(1, $this->svgDrawer->getProperty('x'));
$this->assertSame(2, $this->svgDrawer->getProperty('y'));
$this->assertSame(3, $this->svgDrawer->getProperty('w'));
$this->assertSame(4, $this->svgDrawer->getProperty('h'));
}
/**
* Test: tokenize
*
* @param mixed $transform
* @param mixed $expected
*
* @dataProvider transformProvider
*/
public function testTransform($transform, $expected)
{
$properties = [
'x' => 0,
'y' => 0,
'w' => 100,
'h' => 100,
];
$this->svgDrawer->startDrawing($properties);
$result = $this->svgDrawer->prepareTransform($transform);
$this->assertArraySame($expected, $result);
}
/**
* @param array $expected
* @param array $result
*/
protected function assertArraySame($expected, $result)
{
if (is_array($expected)) {
foreach ($expected as $key => $value) {
$expected[$key] = round($value, 5);
}
}
if (is_array($result)) {
foreach ($result as $key => $value) {
$result[$key] = round($value, 5);
}
}
$this->assertSame($expected, $result);
}
/**
* provider: tokenize
*
* @return array
*/
public function transformProvider()
{
return array(
array(
false,
null
),
array(
'no instruction',
null
),
array(
'foo(1,2)',
null
),
array(
'before scale( 0.1 , 0.2 ) after',
[
0.1, 0.,
0., 0.2,
0., 0.
]
),
array(
'scale(0.1,0.2)',
[
0.1, 0.,
0., 0.2,
0., 0.
]
),
array(
'scale(0.1)',
[
0.1, 0.,
0., 0.1,
0., 0.
]
),
array(
'scale(,)',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'scale()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'translate()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'translate(10mm)',
[
1., 0.,
0., 1.,
10., 0.
]
),
array(
'translate(10mm, 20mm)',
[
1., 0.,
0., 1.,
10., 20.
]
),
array(
'rotate()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'rotate(90)',
[
0., 1.,
-1., 0.,
0., 0.
]
),
array(
'rotate(180)',
[
-1., 0.,
0., -1.,
0., 0.
]
),
array(
'rotate(180, 10mm, 10mm)',
[
-1., 0.,
0., -1.,
-20., -20.
]
),
array(
'skewx()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'skewx(45)',
[
1., 0.,
1., 1.,
0., 0.
]
),
array(
'skewy()',
[
1., 0.,
0., 1.,
0., 0.
]
),
array(
'skewy(45)',
[
1., 1.,
0., 1.,
0., 0.
]
),
array(
'matrix()',
[
0., 0.,
0., 0.,
0., 0.
]
),
array(
'matrix(1,2,3,4,5%,6%)',
[
1., 2.,
3., 4.,
5., 6.
]
),
);
}
}

View File

@ -0,0 +1,99 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Div Tag test
*/
class DivTest extends AbstractTest
{
/**
* test No Break
*
* @return void
*/
public function testNoBreak()
{
$html = '<p>First Tag</p>';
$html.= '<div>Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(1, $object->getNbPages());
}
/**
* test Break Before
*
* @return void
*/
public function testBreakBefore()
{
$html = '<p>First Tag</p>';
$html.= '<div style="page-break-before:always">Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(2, $object->getNbPages());
}
/**
* test Break After
*
* @return void
*/
public function testBreakAfter()
{
$html = '<p>First Tag</p>';
$html.= '<div style="page-break-after:always">Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(2, $object->getNbPages());
}
/**
* test Break before and After
*
* @return void
*/
public function testBreakBeforeAndAfter()
{
$html = '<p>First Tag</p>';
$html.= '<div style="page-break-before:always; page-break-after:always">Second Tag</div>';
$html.= '<p>Third Tag</p>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
$this->assertSame(3, $object->getNbPages());
}
}

View File

@ -0,0 +1,77 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class Thead must not be empty
*/
class MustHaveTagsTest extends AbstractTest
{
/**
* test
*
* @return void
*/
public function testOk()
{
$html = '<table>';
$html.= '<thead><tr><td>Hello</td></tr></thead>';
$html.= '<tbody><tr><td>World</td></tr></tbody>';
$html.= '</table>';
$object = $this->getObject();
$object->writeHTML($html);
$result = $object->output('test.pdf', 'S');
$this->assertNotEmpty($result);
}
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testNotEmptyThead()
{
$html = '<table>';
$html.= '<thead></thead>';
$html.= '<tbody><tr><td>World</td></tr></tbody>';
$html.= '</table>';
$object = $this->getObject();
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testNotEmptyTfoot()
{
$html = '<table>';
$html.= '<tfoot></tfoot>';
$html.= '<tbody><tr><td>World</td></tr></tbody>';
$html.= '</table>';
$object = $this->getObject();
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class CircleErrorTest
*/
class CircleErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<circle />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class EllipseErrorTest
*/
class EllipseErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<ellipse />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class GErrorTest
*/
class GErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<g />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class LineErrorTest
*/
class LineErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<line />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PathErrorTest
*/
class PathErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<path />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PathInvalidTest
*/
class PathInvalidTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$html = '
<page>
<draw style="width:150mm; height:100mm;">
<path style="fill:#770000; stroke:#AA0033;" d="n 20mm,40mm a16mm,8mm 0,0,0 16mm,8mm" />
</draw>
</page>';
$object = $this->getObject();
$object->writeHTML($html);
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PolygonErrorTest
*/
class PolygonErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<polygon />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class PolylineErrorTest
*/
class PolylineErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<polyline />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag\Svg;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class RectErrorTest
*/
class RectErrorTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\HtmlParsingException
*/
public function testCase()
{
$object = $this->getObject();
$object->writeHTML('<rect />');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Html2Pdf Library - Tests
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
namespace Spipu\Html2Pdf\Tests\Tag;
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Tests\AbstractTest;
/**
* Class TdTooLongTest
*/
class TdTooLongTest extends AbstractTest
{
/**
* test
*
* @return void
* @expectedException \Spipu\Html2Pdf\Exception\TableException
*/
public function testCase()
{
$sentence = 'Hello World ! ';
$sentences = '';
for ($k=0; $k<100; $k++) {
$sentences.= $sentence;
}
$object = $this->getObject();
$object->writeHTML('<table><tr><td style="width: 28mm">'.$sentences.'</td></tr></table>');
$object->output('test.pdf', 'S');
}
}

View File

@ -0,0 +1,277 @@
<?php
//============================================================+
// File name : tcpdf_config.php
// Begin : 2004-06-11
// Last Update : 2013-02-06
//
// Description : Configuration file for TCPDF.
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
// Copyright (C) 2004-2013 Nicola Asuni - Tecnick.com LTD
//
// This file is part of TCPDF software library.
//
// TCPDF is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// TCPDF is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
//
// See LICENSE.TXT file for more information.
//============================================================+
/**
* Configuration file for TCPDF.
* @author Nicola Asuni
* @package com.tecnick.tcpdf
* @version 4.9.005
* @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 (e.g. '/var/www')
$_SERVER['DOCUMENT_ROOT'] = '/var/www';
}
}
// be sure that the end slash is present
$_SERVER['DOCUMENT_ROOT'] = str_replace('//', '/', $_SERVER['DOCUMENT_ROOT'].'/');
/**
* Installation path of tcpdf with composer.
*/
$vendorFolders = array(
dirname(dirname(dirname(__FILE__))) . '/vendor/',
dirname(dirname(dirname(__FILE__))) . '/../../',
);
foreach ($vendorFolders as $vendorFolder) {
if (file_exists($vendorFolder.'autoload.php')) {
$k_path_main = $vendorFolder . 'tecnickcom/tcpdf/';
break;
}
}
if (!isset($k_path_main)) {
echo "
[ERROR]
It seems that Html2Pdf dependencies are not installed...
you must install thems with `composer install`
";
exit;
}
define('K_PATH_MAIN', $k_path_main);
// Automatic calculation for the following K_PATH_URL constant
$k_path_url = $k_path_main; // default value for console mode
if (isset($_SERVER['HTTP_HOST']) and (!empty($_SERVER['HTTP_HOST']))) {
if (isset($_SERVER['HTTPS']) and (!empty($_SERVER['HTTPS'])) and strtolower($_SERVER['HTTPS']) !== 'off') {
$k_path_url = 'https://';
} else {
$k_path_url = 'http://';
}
$k_path_url .= $_SERVER['HTTP_HOST'];
$k_path_url .= 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', $k_path_url);
/**
* 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 (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 respect 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);
/**
* if true and PHP version is greater than 5, then the Error() method throw new exception instead of terminating the execution.
*/
define('K_TCPDF_THROW_EXCEPTION_ERROR', true);
}
//============================================================+
// END OF FILE
//============================================================+

View File

@ -0,0 +1,5 @@
"pdf01","Document generat el [[date_d]]/[[date_m]]/[[date_y]]"
"pdf02","Document generat a les [[date_h]]:[[date_i]]"
"pdf03","Document generat el [[date_d]]/[[date_m]]/[[date_y]] a les [[date_h]]:[[date_i]]"
"pdf04","Pàgina [[page_cu]]/[[page_nb]]"
"pdf05","Els formularis requereixen l'ús de l'Adobe Reader 9"
1 pdf01 Document generat el [[date_d]]/[[date_m]]/[[date_y]]
2 pdf02 Document generat a les [[date_h]]:[[date_i]]
3 pdf03 Document generat el [[date_d]]/[[date_m]]/[[date_y]] a les [[date_h]]:[[date_i]]
4 pdf04 Pàgina [[page_cu]]/[[page_nb]]
5 pdf05 Els formularis requereixen l'ús de l'Adobe Reader 9

View File

@ -0,0 +1,5 @@
pdf01,文稿生成日期 [[date_y]]-[[date_m]]-[[date_d]]
pdf02,文稿生成时间 [[date_h]]:[[date_i]]
pdf03,文稿生成于 [[date_y]]-[[date_m]]-[[date_d]] at [[date_h]]:[[date_i]]
pdf04,页 [[page_cu]]/[[page_nb]]
pdf05,表单需要使用 Adobe Reader 9
1 pdf01 文稿生成日期 [[date_y]]-[[date_m]]-[[date_d]]
2 pdf02 文稿生成时间 [[date_h]]:[[date_i]]
3 pdf03 文稿生成于 [[date_y]]-[[date_m]]-[[date_d]] at [[date_h]]:[[date_i]]
4 pdf04 页 [[page_cu]]/[[page_nb]]
5 pdf05 表单需要使用 Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Dokument vytvořen dne [[date_d]].[[date_m]].[[date_y]]"
"pdf02","Dokument vytvořen v [[date_h]]:[[date_i]]"
"pdf03","Dokument vytvořen dne [[date_d]].[[date_m]].[[date_y]] v [[date_h]]:[[date_i]]"
"pdf04","Stránka [[page_cu]]/[[page_nb]]"
"pdf05","Formuláře vyžadují Adobe Reader 9"
1 pdf01 Dokument vytvořen dne [[date_d]].[[date_m]].[[date_y]]
2 pdf02 Dokument vytvořen v [[date_h]]:[[date_i]]
3 pdf03 Dokument vytvořen dne [[date_d]].[[date_m]].[[date_y]] v [[date_h]]:[[date_i]]
4 pdf04 Stránka [[page_cu]]/[[page_nb]]
5 pdf05 Formuláře vyžadují Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Siden oprettet d. [[date_y]]-[[date_m]]-[[date_d]]"
"pdf02","Siden oprettet d. [[date_h]]:[[date_i]]"
"pdf03","Siden oprettet d. [[date_y]]-[[date_m]]-[[date_d]] at [[date_h]]:[[date_i]]"
"pdf04","Side [[page_cu]]/[[page_nb]]"
"pdf05","De formularer kræver brug af Adobe Reader 9"
1 pdf01 Siden oprettet d. [[date_y]]-[[date_m]]-[[date_d]]
2 pdf02 Siden oprettet d. [[date_h]]:[[date_i]]
3 pdf03 Siden oprettet d. [[date_y]]-[[date_m]]-[[date_d]] at [[date_h]]:[[date_i]]
4 pdf04 Side [[page_cu]]/[[page_nb]]
5 pdf05 De formularer kræver brug af Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Datei erstellt am [[date_d]].[[date_m]].[[date_y]]"
"pdf02","Datei erstellt um [[date_h]]:[[date_m]]"
"pdf03","Datei erstellt am [[date_d]].[[date_m]].[[date_y]] um [[date_h]]:[[date_i]]"
"pdf04","Seite [[page_cu]]/[[page_nb]]"
"pdf05","Die Formulare in dieser Datei benötigen den Adobe Reader 9"
1 pdf01 Datei erstellt am [[date_d]].[[date_m]].[[date_y]]
2 pdf02 Datei erstellt um [[date_h]]:[[date_m]]
3 pdf03 Datei erstellt am [[date_d]].[[date_m]].[[date_y]] um [[date_h]]:[[date_i]]
4 pdf04 Seite [[page_cu]]/[[page_nb]]
5 pdf05 Die Formulare in dieser Datei benötigen den Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Document generated on [[date_y]]-[[date_m]]-[[date_d]]"
"pdf02","Document generated at [[date_h]]:[[date_i]]"
"pdf03","Document generated on [[date_y]]-[[date_m]]-[[date_d]] at [[date_h]]:[[date_i]]"
"pdf04","Page [[page_cu]]/[[page_nb]]"
"pdf05","The forms require the use of Adobe Reader 9"
1 pdf01 Document generated on [[date_y]]-[[date_m]]-[[date_d]]
2 pdf02 Document generated at [[date_h]]:[[date_i]]
3 pdf03 Document generated on [[date_y]]-[[date_m]]-[[date_d]] at [[date_h]]:[[date_i]]
4 pdf04 Page [[page_cu]]/[[page_nb]]
5 pdf05 The forms require the use of Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Documento generado el [[date_d]]/[[date_m]]/[[date_y]]"
"pdf02","Documento generado a las [[date_h]]:[[date_i]]"
"pdf03","Documento generado el [[date_d]]/[[date_m]]/[[date_y]] a las [[date_h]]:[[date_i]]"
"pdf04","Página [[page_cu]]/[[page_nb]]"
"pdf05","Los formularios requieren el uso de Adobe Reader 9"
1 pdf01 Documento generado el [[date_d]]/[[date_m]]/[[date_y]]
2 pdf02 Documento generado a las [[date_h]]:[[date_i]]
3 pdf03 Documento generado el [[date_d]]/[[date_m]]/[[date_y]] a las [[date_h]]:[[date_i]]
4 pdf04 Página [[page_cu]]/[[page_nb]]
5 pdf05 Los formularios requieren el uso de Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Dokumentti luotu [[date_y]]-[[date_m]]-[[date_d]]"
"pdf02","Dokumentti luotu [[date_h]]:[[date_i]]"
"pdf03","Dokumentti luotu [[date_y]]-[[date_m]]-[[date_d]] klo [[date_h]]:[[date_i]]"
"pdf04","Sivu [[page_cu]]/[[page_nb]]"
"pdf05","Lomakkeet edellyttävät Adobe Reader 9 käyttöä"
1 pdf01 Dokumentti luotu [[date_y]]-[[date_m]]-[[date_d]]
2 pdf02 Dokumentti luotu [[date_h]]:[[date_i]]
3 pdf03 Dokumentti luotu [[date_y]]-[[date_m]]-[[date_d]] klo [[date_h]]:[[date_i]]
4 pdf04 Sivu [[page_cu]]/[[page_nb]]
5 pdf05 Lomakkeet edellyttävät Adobe Reader 9 käyttöä

View File

@ -0,0 +1,5 @@
"pdf01","Document généré le [[date_d]]/[[date_m]]/[[date_y]]"
"pdf02","Document généré à [[date_h]]:[[date_i]]"
"pdf03","Document généré le [[date_d]]/[[date_m]]/[[date_y]] à [[date_h]]:[[date_i]]"
"pdf04","Page [[page_cu]]/[[page_nb]]"
"pdf05","Les formulaires nécessitent l'utilisation de Adobe Reader 9"
1 pdf01 Document généré le [[date_d]]/[[date_m]]/[[date_y]]
2 pdf02 Document généré à [[date_h]]:[[date_i]]
3 pdf03 Document généré le [[date_d]]/[[date_m]]/[[date_y]] à [[date_h]]:[[date_i]]
4 pdf04 Page [[page_cu]]/[[page_nb]]
5 pdf05 Les formulaires nécessitent l'utilisation de Adobe Reader 9

View File

@ -0,0 +1,5 @@
"pdf01","Documento generato il [[date_d]]/[[date_m]]/[[date_y]]"
"pdf02","Documento generato [[date_h]]:[[date_i]]"
"pdf03","Documento generato il [[date_d]]/[[date_m]]/[[date_y]] nel [[date_h]]:[[date_i]]"
"pdf04","Pagina [[page_cu]]/[[page_nb]]"
"pdf05","I moduli richiedono l'uso di Adobe Reader 9"
1 pdf01 Documento generato il [[date_d]]/[[date_m]]/[[date_y]]
2 pdf02 Documento generato [[date_h]]:[[date_i]]
3 pdf03 Documento generato il [[date_d]]/[[date_m]]/[[date_y]] nel [[date_h]]:[[date_i]]
4 pdf04 Pagina [[page_cu]]/[[page_nb]]
5 pdf05 I moduli richiedono l'uso di Adobe Reader 9

Some files were not shown because too many files have changed in this diff Show More