Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving generation performances #456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/Html2Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ class Html2Pdf
/**
* @var Html2Pdf
*/
static protected $_subobj = null; // object html2pdf prepared in order to accelerate the creation of sub html2pdf
static protected $_tables = array(); // static table to prepare the nested html tables
static protected $_subobj = null; // object html2pdf prepared in order to accelerate the creation of sub html2pdf
static protected $_tables = array(); // static table to prepare the nested html tables
static protected $_tmpFilesAreCleaned = false; // flag : file cleaning is done
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there are some additional white spaces here.


/**
* list of tag definitions
Expand Down Expand Up @@ -231,6 +232,21 @@ public function __construct(

return $this;
}

/**
* Default destructor.
* Clean cache files once, at the end of the pdf generation
* @public
*/
public function __destruct() {
if($this->_isSubPart || self::$_tmpFilesAreCleaned) return;
// remove all temporary files
$tmpfiles = glob(K_PATH_CACHE.'__tcpdf_'.$this->pdf->getFileId().'_*');
if (!empty($tmpfiles)) {
self::$_tmpFilesAreCleaned = true;
array_map('unlink', $tmpfiles);
}
}

/**
* Gets the detailed version as array
Expand Down
52 changes: 52 additions & 0 deletions src/MyPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,58 @@ public function __construct(
$this->setCellPaddings(0, 0, 0, 0);
$this->setCellMargins(0, 0, 0, 0);
}

/**
* Default destructor.
* OVERWRITE TCPDF __destruct
* @public
* @since 1.53.0.TC016
*/
public function __destruct() {
// cleanup
$this->_destroy(true);
}

/**
* OVERWRITE TCPDF _destroy
* tcpdf
*/
public function _destroy($destroyall=false, $preserve_objcopy=false) {
// restore internal encoding
if (isset($this->internal_encoding) AND !empty($this->internal_encoding)) {
mb_internal_encoding($this->internal_encoding);
}
$preserve = array(
'file_id',
'internal_encoding',
'state',
'bufferlen',
'buffer',
'cached_files',
'sign',
'signature_data',
'signature_max_length',
'byterange_string',
'tsa_timestamp',
'tsa_data'
);
foreach (array_keys(get_object_vars($this)) as $val) {
if ($destroyall OR !in_array($val, $preserve)) {
if ((!$preserve_objcopy OR ($val != 'objcopy')) AND ($val != 'file_id') AND isset($this->$val)) {
unset($this->$val);
}
}
}
}

/**
* Get the private variable file_id, for cleaning tmp files
* @access public
*/
Comment on lines +112 to +114
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The * should be in line, but different amounts of white spaces are used for each line.

public function getFileId()
{
return $this->file_id;
}

/**
* Set the parameters for the automatic footer
Expand Down