abstract class PdfGeneratorBase in PDF generator API 2.x
Same name and namespace in other branches
- 8 src/Plugin/PdfGeneratorBase.php \Drupal\pdf_api\Plugin\PdfGeneratorBase
Provides a base class for PDF generator plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\pdf_api\Plugin\PdfGeneratorBase implements PdfGeneratorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PdfGeneratorBase
4 files declare their use of PdfGeneratorBase
- DompdfGenerator.php in src/
Plugin/ PdfGenerator/ DompdfGenerator.php - Contains \Drupal\pdf_api\Plugin\DompdfGenerator.
- MpdfGenerator.php in src/
Plugin/ PdfGenerator/ MpdfGenerator.php - Contains \Drupal\pdf_api\Plugin\MpdfGenerator.
- TcpdfGenerator.php in src/
Plugin/ PdfGenerator/ TcpdfGenerator.php - Contains \Drupal\pdf_api\Plugin\TcpdfGenerator.
- WkhtmltopdfGenerator.php in src/
Plugin/ PdfGenerator/ WkhtmltopdfGenerator.php - Contains \Drupal\pdf_api\Plugin\WkhtmltopdfGenerator.
File
- src/
Plugin/ PdfGeneratorBase.php, line 19 - Contains \Drupal\printable\Plugin\PrintableFormatBase.
Namespace
Drupal\pdf_api\PluginView source
abstract class PdfGeneratorBase extends PluginBase implements PdfGeneratorInterface {
/**
* The global options for the PDF generator.
*
* @var array
*/
protected $options = array();
/**
* {@inheritdoc}
*/
public function getId() {
return $this->pluginDefinition['id'];
}
/**
* {@inheritdoc}
*/
public function getLabel() {
return $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->pluginDefinition['description'];
}
/**
* Get the dimensions of a given page size.
*
* @param string $page_size
* The page size to get the dimensions for (e.g. A4).
*
* @return array|FALSE
* An array with the keys "width" and "height" that contain the width and
* height dimensions respectively. False if the page size is unknown.
*/
protected function getPageDimensions($page_size) {
if ($this
->isValidPageSize($page_size)) {
$page_sizes = $this
->pageSizes();
return $page_sizes[$page_size];
}
}
/**
* Checks if a given page size is valid.
*
* @param string $page_size
* The page size to check.
*
* @return bool
* TRUE if the page size is valid, FALSE if not.
*/
protected function isValidPageSize($page_size) {
return array_key_exists($page_size, $this
->pageSizes());
}
/**
* Get an array of all valid page sizes, keyed by the page size name.
*
* @return array
* An array of page sizes with the values an array of width and height and
* keys the page size name (e.g. A4).
*/
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,
),
);
}
/**
* Get stderr from teh command that was run.
*
* @return string
* Content of stderr output.
*/
public function getStderr() {
return '';
}
/**
* Get stdout from the command that was run.
*
* @return string
* Content of stdout.
*/
public function getStdout() {
return '';
}
/**
* Display error messages.
*
* @return boolean
* Whether any errors occurred and were not ignored.
*/
public function displayErrors() {
$error = $this
->getStderr();
if ($error && !$this->generator->ignoreWarnings) {
// Add stdOut contents - they might help.
$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;
}
/**
* Set global options.
*
* @param array $options
* The array of options to merge into the currently set options.
*/
public function setOptions(array $options) {
$this->options += $options;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PdfGeneratorBase:: |
protected | property | The global options for the PDF generator. | |
PdfGeneratorBase:: |
public | function |
Display error messages. Overrides PdfGeneratorInterface:: |
|
PdfGeneratorBase:: |
public | function |
Returns the administrative description for this generator plugin. Overrides PdfGeneratorInterface:: |
|
PdfGeneratorBase:: |
public | function |
Returns the administrative id for this generator plugin. Overrides PdfGeneratorInterface:: |
|
PdfGeneratorBase:: |
public | function |
Returns the administrative label for this generator plugin. Overrides PdfGeneratorInterface:: |
|
PdfGeneratorBase:: |
protected | function | Get the dimensions of a given page size. | |
PdfGeneratorBase:: |
public | function |
Get stderr from teh command that was run. Overrides PdfGeneratorInterface:: |
1 |
PdfGeneratorBase:: |
public | function |
Get stdout from the command that was run. Overrides PdfGeneratorInterface:: |
1 |
PdfGeneratorBase:: |
protected | function | Checks if a given page size is valid. | |
PdfGeneratorBase:: |
protected | function | Get an array of all valid page sizes, keyed by the page size name. | |
PdfGeneratorBase:: |
public | function | Set global options. | |
PdfGeneratorInterface:: |
public | function | Add a page to the generated PDF. | 4 |
PdfGeneratorInterface:: |
public | function | Returns instances of PDF libraries. | 4 |
PdfGeneratorInterface:: |
constant | Landscape paper orientation. | ||
PdfGeneratorInterface:: |
constant | Portrait paper orientation. | ||
PdfGeneratorInterface:: |
public | function | Generate and save the PDF at a specific location. | 4 |
PdfGeneratorInterface:: |
public | function | The name of the file to be downloaded. | 4 |
PdfGeneratorInterface:: |
public | function | Sets the footer in the PDF. | 4 |
PdfGeneratorInterface:: |
public | function | Sets the header in the PDF. | 4 |
PdfGeneratorInterface:: |
public | function | Set the paper orientation of the generated PDF pages. | 4 |
PdfGeneratorInterface:: |
public | function | Set the page size of the generated PDF pages. | 4 |
PdfGeneratorInterface:: |
public | function | Set the various options for PDF. | 4 |
PdfGeneratorInterface:: |
public | function | Stream the PDF to the browser. | 4 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |