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

[TASK] added hook, composer changes #65

Open
wants to merge 5 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
6 changes: 6 additions & 0 deletions Classes/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace Mittwald\Web2pdf\Options;

use Mittwald\Web2pdf\View\PdfView;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;


Expand Down Expand Up @@ -71,6 +72,11 @@ public function initializeObject() {
$this->mergeReplaceConfiguration($this->options['pdfStrSearch.'], $this->options['pdfStrReplace.'], PdfView::STR_REPLACEMENT_KEY);
unset($this->options['pdfStrSearch.'], $this->options['pdfStrReplace.']);
}

if (is_array($this->options['includeFonts.'])) {
$this->options['includeFonts'] = GeneralUtility::removeDotsFromTS($this->options['includeFonts.']);
unset($this->options['includeFonts.']);
}
}

}
Expand Down
100 changes: 90 additions & 10 deletions Classes/View/PdfView.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class PdfView
*/
protected $objectManager;

/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
* @inject
*/
protected $signalSlotDispatcher;

/**
* @throws \InvalidArgumentException
*/
Expand Down Expand Up @@ -104,17 +110,33 @@ public function renderHtmlOutput($content, $pageTitle)
$pdf->WriteHTML($content);
$pdf->Output($filePath, 'F');

$fileName = $this->fileNameUtility->convert($pageTitle);
$continueOutput = true;

$this->dispatch(
'afterPdfGeneration',
[
&$destination,
&$fileName,
&$filePath,
&$continueOutput,
$this
]
);

if ($continueOutput === true) {
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Type: application/pdf', false);
header('Content-Disposition: ' . $destination . '; filename="' . $fileName . '.pdf' . '"');
readfile($filePath);
unlink($filePath);
}

header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Type: application/pdf', false);
header('Content-Disposition: ' . $destination . '; filename="' . $this->fileNameUtility->convert($pageTitle) . '.pdf' . '"');
readfile($filePath);
unlink($filePath);
exit;
}

Expand Down Expand Up @@ -142,6 +164,59 @@ private function replaceStrings($content)
return $this->pdfLinkUtility->replace($content);
}

/**
* Call hook and change arguments value if returned
*
* @param $signalName
* @param $arguments
* @return void
*/
private function dispatch($signalName, $arguments)
{
$slotReturn = $this->signalSlotDispatcher->dispatch(
__CLASS__,
$signalName,
$arguments
);

if ($slotReturn) {
foreach ($slotReturn as $key => $itemReturn) {
$arguments[$key] = $itemReturn;
}
}
}

/**
* Add fonts
*
* @param \mPDF $pdf
* @param array $fonts
* @return void
*/
private function includeFonts(\mPDF $pdf, $fonts)
{
foreach ($fonts as $f => $fs) {
// add to fontdata array
$pdf->fontdata[$f] = $fs;

// add to available fonts array
if (isset($fs['R']) && $fs['R']) {
$pdf->available_unifonts[] = $f;
}
if (isset($fs['B']) && $fs['B']) {
$pdf->available_unifonts[] = $f.'B';
}
if (isset($fs['I']) && $fs['I']) {
$pdf->available_unifonts[] = $f.'I';
}
if (isset($fs['BI']) && $fs['BI']) {
$pdf->available_unifonts[] = $f.'BI';
}
}

$pdf->default_available_fonts = $pdf->available_unifonts;
}

/**
* Returns configured mPDF object
*
Expand All @@ -157,6 +232,7 @@ protected function getPdfObject()
$rightMargin = ($this->options->getPdfRightMargin()) ? $this->options->getPdfRightMargin() : '15';
$topMargin = ($this->options->getPdfTopMargin()) ? $this->options->getPdfTopMargin() : '15';
$styleSheet = ($this->options->getPdfStyleSheet()) ? $this->options->getPdfStyleSheet() : 'print';
$includeFonts = ($this->options->getIncludeFonts()) ? $this->options->getIncludeFonts() : null;

/* @var $pdf \mPDF */
$pdf = $this->objectManager->get(
Expand All @@ -176,6 +252,10 @@ protected function getPdfObject()

$pdf->SetMargins($leftMargin, $rightMargin, $topMargin);

if (is_array($includeFonts) && !empty($includeFonts)) {
$this->includeFonts($pdf, $includeFonts);
}

if ($styleSheet == 'print' || $styleSheet == 'screen') {
$pdf->CSSselectMedia = $styleSheet;
} else {
Expand Down
4 changes: 4 additions & 0 deletions Configuration/TypoScript/setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ plugin.tx_web2pdf {
useCustomHeader = {$plugin.tx_web2pdf.settings.useCustomHeader}
useCustomFooter = {$plugin.tx_web2pdf.settings.useCustomFooter}

includeFonts {

}

pdfPregSearch {
1 =
}
Expand Down
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"type": "typo3-cms-extension",
"require": {
"php": ">=5.3.2",
"typo3/cms-core": "~6.2.14|>=7.4.0,<8.0",
"mpdf/mpdf": "6.0"
"typo3/cms-core": "~6.2.14|>=7.4.0",
"mpdf/mpdf": "6.1.3"
},
"require-dev": {
"namelesscoder/typo3-repository-client": "1.1.x-dev",
Expand All @@ -20,10 +20,7 @@
"autoload": {
"psr-4": {
"Mittwald\\Web2pdf\\": "Classes"
},
"classmap": [
"Vendor/mpdf/mpdf"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down