You are here

function TCPDFDrupal::DrupalInitialize in TCPDF 8

Sets a bunch of commonly used propeties in the TCPDF object. The propeties set by this function can be safely changed after calling the method. This method also let's the developer to change the header or footer of the pdf document without making his/her own class.

Parameters

array $options: Associative array containing basic settings. 'title' => Title of the document 'subject' => Subject of the document 'author' => Author of the document 'logo_path' => Path to a logo wich is placed to the header 'keywords' => Comma separated list of keywords 'header' => Array 'html' => Html code of the header. 'callback' => Function that generates the header. If 'html' is set, it's ignored. Note: Not working. 'footer' => Array 'html' => Html code of the footer. 'callback' => Function that generates the footer. If 'html' is set, it's ignored. Note: Not working.

File

src/TCPDFDrupal.php, line 50
Contains \TCPDF\TCPDFDrupal.

Class

TCPDFDrupal
Do not create a new instance of this class manually. Use tcpdf_get_instance().

Namespace

Drupal\tcpdf

Code

function DrupalInitialize($options) {
  $site_name = \Drupal::config('system.site')
    ->get('name');
  $title = isset($options['title']) ? $options['title'] : $site_name;
  $author = isset($options['author']) ? $options['author'] : $site_name;
  $subject = isset($options['subject']) ? $options['subject'] : $site_name;
  $keywords = isset($options['keywords']) ? $options['keywords'] : 'pdf, drupal';
  $this->drupalHeader = isset($options['header']) ? $options['header'] : $this->drupalHeader;
  $this->drupalFooter = isset($options['footer']) ? $options['footer'] : $this->drupalFooter;

  // set document information
  $this
    ->SetCreator(PDF_CREATOR);
  $this
    ->SetAuthor($author);
  $this
    ->SetTitle($title);
  $this
    ->SetSubject($subject);
  $this
    ->SetKeywords($keywords);

  // set default header data
  $this
    ->setFooterFont(array(
    PDF_FONT_NAME_DATA,
    '',
    6,
  ));

  // set default monospaced font
  $this
    ->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

  //set margins
  $this
    ->SetMargins(PDF_MARGIN_LEFT, 28, PDF_MARGIN_RIGHT);
  $this
    ->SetHeaderMargin(PDF_MARGIN_HEADER);
  $this
    ->SetFooterMargin(PDF_MARGIN_FOOTER);

  //set auto page breaks
  $this
    ->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

  //set image scale factor
  $this
    ->setImageScale(PDF_IMAGE_SCALE_RATIO);

  // set font
  $this
    ->SetFont('dejavusans', '', 8);
  $this
    ->AddPage();
}