You are here

public function PhpWkhtmlToPdf::__construct in Entity Print 8.2

Constructs a \Drupal\Component\Plugin\PluginBase object.

Parameters

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin_id for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Overrides PrintEngineBase::__construct

File

src/Plugin/EntityPrint/PrintEngine/PhpWkhtmlToPdf.php, line 59

Class

PhpWkhtmlToPdf
PHP wkhtmltopdf plugin.

Namespace

Drupal\entity_print\Plugin\EntityPrint\PrintEngine

Code

public function __construct(array $configuration, $plugin_id, $plugin_definition, ExportTypeInterface $export_type) {
  parent::__construct($configuration, $plugin_id, $plugin_definition, $export_type);
  $this->pdf = new Pdf([
    'binary' => $this->configuration['binary_location'],
    'orientation' => $this->configuration['orientation'],
    'username' => $this->configuration['username'],
    'password' => $this->configuration['password'],
    'page-size' => $this->configuration['default_paper_size'],
    'zoom' => $this->configuration['zoom'],
    'viewport-size' => $this->configuration['viewport_size'],
  ]);
  if ($this->configuration['remove_pdf_margins']) {
    $this->pdf
      ->setOptions([
      'margin-top' => 0,
      'margin-bottom' => 0,
      'margin-left' => 0,
      'margin-right' => 0,
    ]);
  }

  // Table of contents handling.
  if ($this->configuration['toc_generate']) {
    if ($this->configuration['toc_enable_back_links']) {

      // This option is actually a page option.
      $this
        ->getPrintObject()
        ->setOptions([
        'enable-toc-back-links',
      ]);
    }
    $options = [];
    if ($this->configuration['toc_disable_dotted_lines']) {
      $options[] = 'disable-dotted-lines';
    }
    if ($this->configuration['toc_disable_links']) {
      $options[] = 'disable-toc-links';
    }
    $this
      ->getPrintObject()
      ->addToc($options);
  }

  // Proxy configuration.
  $config = Settings::get('http_client_config');
  if (!empty($config['proxy']['https'])) {
    $this->pdf
      ->setOptions([
      'proxy' => $config['proxy']['https'],
    ]);
  }
  elseif (!empty($config['proxy']['http'])) {
    $this->pdf
      ->setOptions([
      'proxy' => $config['proxy']['http'],
    ]);
  }
}