class WkhtmltopdfGenerator in PDF generator API 8
Same name and namespace in other branches
- 2.x src/Plugin/PdfGenerator/WkhtmltopdfGenerator.php \Drupal\pdf_api\Plugin\PdfGenerator\WkhtmltopdfGenerator
A PDF generator plugin for the WKHTMLTOPDF library.
Plugin annotation
@PdfGenerator(
id = "wkhtmltopdf",
module = "pdf_api",
title = @Translation("WKHTMLTOPDF"),
description = @Translation("PDF generator using the WKHTMLTOPDF binary.")
)
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\pdf_api\Plugin\PdfGenerator\WkhtmltopdfGenerator implements ContainerFactoryPluginInterface
- class \Drupal\pdf_api\Plugin\PdfGeneratorBase implements PdfGeneratorInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of WkhtmltopdfGenerator
File
- src/
Plugin/ PdfGenerator/ WkhtmltopdfGenerator.php, line 30 - Contains \Drupal\pdf_api\Plugin\WkhtmltopdfGenerator.
Namespace
Drupal\pdf_api\Plugin\PdfGeneratorView source
class WkhtmltopdfGenerator extends PdfGeneratorBase implements ContainerFactoryPluginInterface {
/**
* Instance of the WKHtmlToPdf class library.
*
* @var \WkHtmlToPdf
*/
protected $generator;
/**
* Instance of the messenger class.
*
* @var \Drupal\Core\Messenger;
*/
protected $messenger;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, Pdf $generator, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->generator = $generator;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('wkhtmltopdf'), $container
->get('messenger'));
}
/**
* Set the path of binary file.
*
* @param string $path_to_binary
* Path to binary file.
*/
public function configBinary($path_to_binary) {
$this
->setOptions(array(
'binary' => $path_to_binary,
));
}
/**
* {@inheritdoc}
*/
public function setter($pdf_content, $pdf_location, $save_pdf, $paper_orientation, $paper_size, $footer_content, $header_content, $path_to_binary = '') {
$this
->configBinary($path_to_binary);
$this
->addPage($pdf_content);
$this
->setPageSize($paper_size);
$this
->setPageOrientation($paper_orientation);
// Uncomment below line when need to add header and footer to page,
// also make changes in the templates too.
// $this->setHeader($header_content);
// $this->setFooter($footer_content);
}
/**
* {@inheritdoc}
*/
public function getObject() {
return $this->generator;
}
/**
* {@inheritdoc}
*/
public function setHeader($text) {
$this
->setOptions(array(
'header-right' => $text,
));
}
/**
* {@inheritdoc}
*/
public function setPageOrientation($orientation = PdfGeneratorInterface::PORTRAIT) {
$this
->setOptions(array(
'orientation' => $orientation,
));
}
/**
* {@inheritdoc}
*/
public function setPageSize($page_size) {
if ($this
->isValidPageSize($page_size)) {
$this
->setOptions(array(
'page-size' => $page_size,
));
}
}
/**
* {@inheritdoc}
*/
public function addPage($html) {
$this->generator
->addPage($html);
}
/**
* {@inheritdoc}
*/
public function setFooter($text) {
$this
->setOptions(array(
'footer-center' => $text,
));
}
/**
* {@inheritdoc}
*/
public function save($location) {
$this
->preGenerate();
$this->generator
->saveAs($location);
}
/**
* {@inheritdoc}
*/
public function send() {
$this
->preGenerate();
$this->generator
->send($this->generator
->getPdfFilename(), true);
}
/**
* {@inheritdoc}
*/
public function stream($filelocation) {
$this
->preGenerate();
$this->generator
->saveAs($filelocation);
$this->generator
->send($filelocation, false);
}
/**
* Set the global options from plugin into the WKHTMLTOPDF generator class.
*/
protected function preGenerate() {
$this->generator
->setOptions($this->options);
}
/**
* Get errors from the generator.
*
* @return string
* The content of the stderr pipe.
*/
public function getStderr() {
return $this->generator
->getError();
}
/**
* Get stdout output from the generator.
*
* @return string
* The content of the stdout pipe.
*/
public function getStdout() {
return $this->generator
->getCommand()
->getOutput();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
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:: |
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:: |
constant | Landscape paper orientation. | ||
PdfGeneratorInterface:: |
constant | Portrait paper orientation. | ||
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:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
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. | |
WkhtmltopdfGenerator:: |
protected | property | Instance of the WKHtmlToPdf class library. | |
WkhtmltopdfGenerator:: |
protected | property |
Instance of the messenger class. Overrides MessengerTrait:: |
|
WkhtmltopdfGenerator:: |
public | function |
Add a page to the generated PDF. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function | Set the path of binary file. | |
WkhtmltopdfGenerator:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Returns instances of PDF libraries. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Get errors from the generator. Overrides PdfGeneratorBase:: |
|
WkhtmltopdfGenerator:: |
public | function |
Get stdout output from the generator. Overrides PdfGeneratorBase:: |
|
WkhtmltopdfGenerator:: |
protected | function | Set the global options from plugin into the WKHTMLTOPDF generator class. | |
WkhtmltopdfGenerator:: |
public | function |
Generate and save the PDF at a specific location. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
The name of the file to be downloaded. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Sets the footer in the PDF. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Sets the header in the PDF. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Set the paper orientation of the generated PDF pages. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Set the page size of the generated PDF pages. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Set the various options for PDF. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Stream the PDF to the browser. Overrides PdfGeneratorInterface:: |
|
WkhtmltopdfGenerator:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |