[TYPO3-dev] pdf_creator2 - custom header / footer and cover (optional)

Alex Ru alex at ruof.org
Fri Sep 19 11:18:01 CEST 2014


Hello all,

I modified the extension pdf_creator2 for usage of custom header, footer and cover (optional) over TS-Constants and html-files. With this you are able to define different header, footer and an optional cover when ever you want over a typo3-template.

The modifications are sent to the developer of the extension and he will include this in the TER version soon, cause source-code edited.

I have used and tested it under typo3 version 4.5.35.

For everybody who can't wait, here are the modifications for you.

> Lines are added
< Lines are removed or commented out

Changes made in source code:
In ext_typoscript_constants.txt added at the end

># extras by A. Ruof for custom header/footer and cover
>pdf_creator2.my_header = typo3conf/ext/pdf_creator2/res/header.html
>pdf_creator2.my_footer = typo3conf/ext/pdf_creator2/res/footer.html
>pdf_creator2.my_coverActive = 0
>pdf_creator2.my_cover = typo3conf/ext/pdf_creator2/res/cover.html

in ext_typoscript_constants.txt added at the end

># extras by A. Ruof for custom header/footer and cover
>config.pdf_creator2.my_header = {$pdf_creator2.my_header}
>config.pdf_creator2.my_footer = {$pdf_creator2.my_footer}
>config.pdf_creator2.my_coverActive = {$pdf_creator2.my_coverActive}
>config.pdf_creator2.my_cover = {$pdf_creator2.my_cover}

in gen_pdf.php added at the end of //---------------------------- parse html2df parameters --------------

># extras by A. Ruof for custom header/footer and cover
>$html2pdf_my_header=$GLOBALS{TSFE}->config['config']['pdf_creator2.']['my_header'];
>$html2pdf_my_footer=$GLOBALS{TSFE}->config['config']['pdf_creator2.']['my_footer'];
>$html2pdf_my_coverActive=$GLOBALS{TSFE}->config['config']['pdf_creator2.']['my_coverActive'];
>$html2pdf_my_cover=$GLOBALS{TSFE}->config['config']['pdf_creator2.']['my_cover'];

In gen_pdf.php Changed the $wkh_params array

># extras by A. Ruof for custom header/footer and cover
>$cover = PATH_site . $html2pdf_my_cover;
$wkh_params = array(
'path' => PATH_site.'typo3temp/',
'page_size' => $html2pdf_size,
> 'coverActive' => $html2pdf_my_coverActive,
> 'cover' => $cover,
'margins' => 
array ( 'left' => $html2pdf_left,
'right' => $html2pdf_right,
'top' => $html2pdf_top,
'bottom' => $html2pdf_bottom
)
);

In gen_pdf.php change the code for paths of header / footer

>// original header footer 
<// $footer = "file://". t3lib_extMgm::extPath('pdf_creator2','res/footer.html?url='.$urll.'&ndate='.$ndate);
<// $header = t3lib_extMgm::extPath('pdf_creator2','res/header.html');

># extras by A. Ruof for custom header/footer and cover
>$footer = 'file://' . PATH_site . $html2pdf_my_footer .'?url='.$urll.'&ndate='.$ndate;
>$header = $html2pdf_my_header;

In class.pc_wkhtmltopdf.php added at getters/setters

># extras by A. Ruof for custom header/footer and cover
>protected $_coverHtml;
>protected $_coverActive = false;

In class.pc_wkhtmltopdf.php at public function __construct(array $options = array()) 
  add before $this->setPath($options['path']);

># extras by A. Ruof for custom header/footer and cover
>if (array_key_exists('cover', $options)) {
> $this->setCoverHtml($options['cover']);
>}
>if (array_key_exists('coverActive', $options)) {
> $this->setCoverActive($options['coverActive']);
>}

After public function getPassword() { ... } add
># extras by A. Ruof for custom header/footer and cover
>public function setCoverHtml($cover)
>{
> $this->_coverHtml = (string)$cover;
> return $this;
>}

>public function getCoverHtml()
>{
> return $this -> _coverHtml;
>}

>public function setCoverActive($coverActive = true)
>{
> $this->_coverActive = (boolean)$coverActive;
> return $this;
>}

>public function getCoverActive()
>{
> return $this->_coverActive;
>}


In class.pc_wkhtmltopdf.php directly before $command .= ' "%input%"'; add

$command .= ($this->getTitle()) ? ' --title "' . $this->getTitle() . '"' : '';

># extras by A. Ruof for custom header/footer and cover
>$command .= ($this->getCoverActive()) ? " cover \"" . $this->getCoverHtml() . "\" " : "";

$command .= ' "%input%"';



Now create a template or add in your template in Constants field:
pdf_creator2.my_header = fileadmin/template/pdf/header.html
pdf_creator2.my_footer = fileadmin/template/pdf/footer.html
pdf_creator2.my_cover = fileadmin/template/pdf/cover.html
pdf_creator2.my_coverActive = 1

if you set this to zero, the cover is disabled (default is disabled over the ext_defaults_constants.txt):
pdf_creator2.my_coverActive = 0

Copy the files header.html and footer.html from typo3conf/ext/pdf_creator2/res/ to fileadmin/template/pdf/. The file cover.html do not exist. Create one.

Greetings

Alex



More information about the TYPO3-dev mailing list