View source
<?php
namespace Drupal\pdf_api\Plugin;
use Drupal\Core\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
abstract class PdfGeneratorBase extends PluginBase implements PdfGeneratorInterface {
protected $options = array();
public function getId() {
return $this->pluginDefinition['id'];
}
public function getLabel() {
return $this->pluginDefinition['title'];
}
public function getDescription() {
return $this->pluginDefinition['description'];
}
protected function getPageDimensions($page_size) {
if ($this
->isValidPageSize($page_size)) {
$page_sizes = $this
->pageSizes();
return $page_sizes[$page_size];
}
}
protected function isValidPageSize($page_size) {
return array_key_exists($page_size, $this
->pageSizes());
}
protected function pageSizes() {
return array(
'A0' => array(
'width' => 0,
'height' => 0,
),
'A1' => array(
'width' => 0,
'height' => 0,
),
'A2' => array(
'width' => 0,
'height' => 0,
),
'A3' => array(
'width' => 0,
'height' => 0,
),
'A4' => array(
'width' => 0,
'height' => 0,
),
'A5' => array(
'width' => 0,
'height' => 0,
),
'A6' => array(
'width' => 0,
'height' => 0,
),
'A7' => array(
'width' => 0,
'height' => 0,
),
'A8' => array(
'width' => 0,
'height' => 0,
),
'A9' => array(
'width' => 0,
'height' => 0,
),
'B0' => array(
'width' => 0,
'height' => 0,
),
'B1' => array(
'width' => 0,
'height' => 0,
),
'B10' => array(
'width' => 0,
'height' => 0,
),
'B2' => array(
'width' => 0,
'height' => 0,
),
'B3' => array(
'width' => 0,
'height' => 0,
),
'B4' => array(
'width' => 0,
'height' => 0,
),
'B5' => array(
'width' => 0,
'height' => 0,
),
'B6' => array(
'width' => 0,
'height' => 0,
),
'B7' => array(
'width' => 0,
'height' => 0,
),
'B8' => array(
'width' => 0,
'height' => 0,
),
'B9' => array(
'width' => 0,
'height' => 0,
),
'C5E' => array(
'width' => 0,
'height' => 0,
),
'Comm10E' => array(
'width' => 0,
'height' => 0,
),
'DLE' => array(
'width' => 0,
'height' => 0,
),
'Executive' => array(
'width' => 0,
'height' => 0,
),
'Folio' => array(
'width' => 0,
'height' => 0,
),
'Ledger' => array(
'width' => 0,
'height' => 0,
),
'Legal' => array(
'width' => 0,
'height' => 0,
),
'Letter' => array(
'width' => 0,
'height' => 0,
),
'Tabloid' => array(
'width' => 0,
'height' => 0,
),
);
}
public function getStderr() {
return '';
}
public function getStdout() {
return '';
}
public function displayErrors() {
$error = $this
->getStderr();
if ($error && !$this->generator->ignoreWarnings) {
$output = $this
->getStdout();
if ($output) {
$output = str_replace("\n", "<br />", $output);
$markup = new TranslatableMarkup('@error<br />Output was:<br />@output', [
'@error' => $error,
'@output' => new FormattableMarkup($output, []),
]);
}
else {
$markup = $error;
}
$this->messenger
->addError($markup);
return true;
}
return false;
}
public function setOptions(array $options) {
$this->options += $options;
}
}