You are here

class TcpdfGenerator in PDF generator API 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/PdfGenerator/TcpdfGenerator.php \Drupal\pdf_api\Plugin\PdfGenerator\TcpdfGenerator

A PDF generator plugin for the mPDF library.

Plugin annotation


@PdfGenerator(
  id = "tcpdf",
  module = "pdf_api",
  title = @Translation("TCPDF"),
  description = @Translation("PDF generator using the TCPDF generator.")
)

Hierarchy

Expanded class hierarchy of TcpdfGenerator

File

src/Plugin/PdfGenerator/TcpdfGenerator.php, line 27
Contains \Drupal\pdf_api\Plugin\TcpdfGenerator.

Namespace

Drupal\pdf_api\Plugin\PdfGenerator
View source
class TcpdfGenerator extends PdfGeneratorBase implements ContainerFactoryPluginInterface {

  /**
   * Instance of the TCPDF class library.
   *
   * @var \TCPDF
   */
  protected $generator;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, TCPDF $generator) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->generator = $generator;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('tcpdf'));
  }

  /**
   * {@inheritdoc}
   */
  public function setter($pdf_content, $pdf_location, $save_pdf, $paper_orientation, $paper_size, $footer_content, $header_content, $path_to_binary = '') {
    $this
      ->setPageOrientation($paper_orientation);
    $this
      ->addPage($pdf_content);
    $this
      ->setFooter("");
  }

  /**
   * {@inheritdoc}
   */
  public function getObject() {
    return $this->generator;
  }

  /**
   * {@inheritdoc}
   */
  public function setHeader($text) {
    $this->generator
      ->SetPrintHeader($text);
  }

  /**
   * {@inheritdoc}
   */
  public function addPage($html) {
    $this->generator
      ->AddPage();
    $this->generator
      ->writeHTML($html);
  }

  /**
   * {@inheritdoc}
   */
  public function setPageOrientation($orientation = PdfGeneratorInterface::PORTRAIT) {
    if ($orientation == 'portrait') {
      $orientation = 'P';
    }
    else {
      $orientation = 'L';
    }
    $this->generator
      ->setPageOrientation($orientation);
  }

  /**
   * {@inheritdoc}
   */
  public function setPageSize($page_size) {
    if ($this
      ->isValidPageSize($page_size)) {
      $this->generator
        ->AddPage("", $page_size, FALSE, TRUE);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setFooter($text) {
    $this->generator
      ->writeHtmlCell("", 3, 20, 4, '<p>Page ' . $this->generator
      ->getAliasNumPage() . ' of  ' . ' ' . $this->generator
      ->getAliasNbPages() . '</p>', '', 1, 0, FALSE, 'R');
  }

  /**
   * {@inheritdoc}
   */
  public function save($location) {
    $this->generator
      ->Output($location, 'F');
  }

  /**
   * {@inheritdoc}
   */
  public function send() {
    $this->generator
      ->Output('htmlout.pdf', 'I');
  }

  /**
   * {@inheritdoc}
   */
  public function stream($filelocation) {
    $this->generator
      ->Output($filelocation, 'D');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PdfGeneratorBase::$options protected property The global options for the PDF generator.
PdfGeneratorBase::displayErrors public function Display error messages. Overrides PdfGeneratorInterface::displayErrors
PdfGeneratorBase::getDescription public function Returns the administrative description for this generator plugin. Overrides PdfGeneratorInterface::getDescription
PdfGeneratorBase::getId public function Returns the administrative id for this generator plugin. Overrides PdfGeneratorInterface::getId
PdfGeneratorBase::getLabel public function Returns the administrative label for this generator plugin. Overrides PdfGeneratorInterface::getLabel
PdfGeneratorBase::getPageDimensions protected function Get the dimensions of a given page size.
PdfGeneratorBase::getStderr public function Get stderr from teh command that was run. Overrides PdfGeneratorInterface::getStderr 1
PdfGeneratorBase::getStdout public function Get stdout from the command that was run. Overrides PdfGeneratorInterface::getStdout 1
PdfGeneratorBase::isValidPageSize protected function Checks if a given page size is valid.
PdfGeneratorBase::pageSizes protected function Get an array of all valid page sizes, keyed by the page size name.
PdfGeneratorBase::setOptions public function Set global options.
PdfGeneratorInterface::LANDSCAPE constant Landscape paper orientation.
PdfGeneratorInterface::PORTRAIT constant Portrait paper orientation.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TcpdfGenerator::$generator protected property Instance of the TCPDF class library.
TcpdfGenerator::addPage public function Add a page to the generated PDF. Overrides PdfGeneratorInterface::addPage
TcpdfGenerator::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
TcpdfGenerator::getObject public function Returns instances of PDF libraries. Overrides PdfGeneratorInterface::getObject
TcpdfGenerator::save public function Generate and save the PDF at a specific location. Overrides PdfGeneratorInterface::save
TcpdfGenerator::send public function The name of the file to be downloaded. Overrides PdfGeneratorInterface::send
TcpdfGenerator::setFooter public function Sets the footer in the PDF. Overrides PdfGeneratorInterface::setFooter
TcpdfGenerator::setHeader public function Sets the header in the PDF. Overrides PdfGeneratorInterface::setHeader
TcpdfGenerator::setPageOrientation public function Set the paper orientation of the generated PDF pages. Overrides PdfGeneratorInterface::setPageOrientation
TcpdfGenerator::setPageSize public function Set the page size of the generated PDF pages. Overrides PdfGeneratorInterface::setPageSize
TcpdfGenerator::setter public function Set the various options for PDF. Overrides PdfGeneratorInterface::setter
TcpdfGenerator::stream public function Stream the PDF to the browser. Overrides PdfGeneratorInterface::stream
TcpdfGenerator::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct