Skip to content

Commit

Permalink
#14 Adds possibility to load html styles from external file
Browse files Browse the repository at this point in the history
  • Loading branch information
maechler committed Apr 20, 2017
1 parent 2585a8e commit 7fc10a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.3.0
- Adds support for TYPO3 8.7 LTS, [#18](https://github.com/bithost-gmbh/pdfviewhelpers/issues/18)
- Adds PageBreakViewHelper, [#16](https://github.com/bithost-gmbh/pdfviewhelpers/issues/16)
- Adds possibility to load html styles from external file, [#14](https://github.com/bithost-gmbh/pdfviewhelpers/issues/14)

## 1.2.3, March 21, 2017
- Fixes configuration manager initialization error, [#19](https://github.com/bithost-gmbh/pdfviewhelpers/issues/19)
Expand Down
26 changes: 25 additions & 1 deletion Classes/ViewHelpers/HtmlViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* * */

use Bithost\Pdfviewhelpers\Exception\ValidationException;

/**
* HtmlViewHelper
*
Expand All @@ -38,18 +40,40 @@ class HtmlViewHelper extends AbstractContentElementViewHelper {
/**
* @return void
*/
public function initializeArguments() {
parent::initializeArguments();

$this->registerArgument('styleSheet', 'string', '', FALSE, $this->settings['html']['styleSheet']);
}

/**
* @return void
*
* @throws ValidationException if an invalid style sheet path is provided
*/
public function render() {
$html = $this->renderChildren();
$htmlStyle = '';
$color = $this->convertHexToRGB($this->settings['generalText']['color']);
$padding = $this->settings['generalText']['padding'];

if (!empty($this->arguments['styleSheet'])) {
$styleSheetPath = PATH_site . $this->arguments['styleSheet'];

if (!file_exists($styleSheetPath) || !is_readable($styleSheetPath)) {
throw new ValidationException('Path to style sheet "' . $styleSheetPath . '" does not exist or file is not readable. ERROR: 1492706529', 1492706529);
}

$htmlStyle = '<style>' . file_get_contents($styleSheetPath) . '</style>';
}

//reset settings to generalText
$this->getPDF()->SetTextColor($color['R'], $color['G'], $color['B']);
$this->getPDF()->SetFontSize($this->settings['generalText']['fontSize']);
$this->getPDF()->SetFont($this->settings['generalText']['fontFamily']);
$this->getPDF()->setCellPaddings($padding['left'], $padding['top'], $padding['right'], $padding['bottom']);

$this->getPDF()->writeHTML($html, TRUE, FALSE, TRUE, FALSE, '');
$this->getPDF()->writeHTML($htmlStyle . $html, TRUE, FALSE, TRUE, FALSE, '');
}

}
3 changes: 3 additions & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ plugin.tx_pdfviewhelpers.settings {
bulletImageSrc =
bulletSize = 1.5
}
html {
styleSheet =
}
}

module.tx_pdfviewhelpers < plugin.tx_pdfviewhelpers
12 changes: 11 additions & 1 deletion Documentation/Configuration/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Properties in plugin.tx_pdfviewhelpers.settings
list.bulletColor_ :ref:`t3tsref:data-type-string` #000
list.bulletImageSrc_ :ref:`t3tsref:data-type-string`
list.bulletSize_ :ref:`t3tsref:data-type-float` 1.5
html.styleSheet_ :ref:`t3tsref:data-type-string`
=============================== ===================================== ==========================================


Expand Down Expand Up @@ -182,7 +183,7 @@ The title of the generated PDF document.
.. _document.subject:

document.subject
""""""""""""""
""""""""""""""""

:typoscript:`plugin.tx_pdfviewhelpers.settings.document.subject =` :ref:`t3tsref:data-type-string`

Expand Down Expand Up @@ -374,6 +375,15 @@ list.bulletSize

The size of the bullet as floating point value.

.. _html.styleSheet:

html.styleSheet
"""""""""""""""

:typoscript:`plugin.tx_pdfviewhelpers.settings.html.styleSheet =` :ref:`t3tsref:data-type-string`

The path to a style sheet being used in the HtmlViewHelper. The path is relative to the webroot directory, e.g. "fileadmin/pdf_style.css".

Advanced Customization
----------------------

Expand Down

0 comments on commit 7fc10a3

Please sign in to comment.