You are here

public function W2PDF::Header in Webform2PDF 6

Same name and namespace in other branches
  1. 6.2 webform2pdf.class.inc \W2PDF::Header()
  2. 7.4 webform2pdf.class.inc \W2PDF::Header()
  3. 7.3 webform2pdf.class.inc \W2PDF::Header()

This method is used to render the page header. It is automatically called by AddPage() and could be overwritten in your own inherited class.

File

./webform2pdf.class.inc, line 104

Class

W2PDF

Code

public function Header() {
  $ormargins = $this
    ->getOriginalMargins();
  $headerfont = $this
    ->getHeaderFont();
  $headerdata = $this
    ->getHeaderData();
  $imgy['left'] = $imgy['right'] = $this
    ->GetY();
  $header_w = 0;
  $empty_header = 1;
  if (!empty($headerdata['logo']['left']) && !empty($headerdata['logo_size']['left']['w'])) {
    if ($headerdata['logo']['left'] and $headerdata['logo']['left'] != K_BLANK_IMAGE) {
      $this
        ->Image(K_PATH_IMAGES . $headerdata['logo']['left'], $this
        ->GetX(), $this
        ->getHeaderMargin(), $headerdata['logo_size']['left']['w']);
      $imgy['left'] = $this
        ->getImageRBY();
      $empty_header = 0;
    }
  }
  if (!empty($headerdata['logo']['left']) && !empty($headerdata['logo_size']['left']['w'])) {
    if ($headerdata['logo']['right'] and $headerdata['logo']['right'] != K_BLANK_IMAGE) {
      $this
        ->Image(K_PATH_IMAGES . $headerdata['logo']['right'], $this
        ->getPageWidth() - $ormargins['right'] - $headerdata['logo_size']['right']['w'], $this
        ->getHeaderMargin(), $headerdata['logo_size']['right']['w']);
      $header_w = $this
        ->getPageWidth() - $ormargins['left'] - $ormargins['right'] - $headerdata['logo_size']['left']['w'] * 1.1 - $headerdata['logo_size']['right']['w'] * 1.1;
      $imgy['right'] = $this
        ->getImageRBY();
      $empty_header = 0;
    }
  }
  $cell_height = round($this
    ->getCellHeightRatio() * $headerfont[2] / $this
    ->getScaleFactor(), 2);

  // set starting margin for text data cell
  if ($this
    ->getRTL()) {
    $header_x = $ormargins['right'] + $headerdata['logo_size']['right']['w'] * 1.1;
  }
  else {
    $header_x = $ormargins['left'] + $headerdata['logo_size']['left']['w'] * 1.1;
  }
  $this
    ->SetTextColor(0, 0, 0);

  // header html string
  $this
    ->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
  $this
    ->SetX($header_x);
  if (!empty($headerdata['string'])) {
    $empty_header = 0;
  }
  $this
    ->writeHTMLCell($header_w, $cell_height, '', '', $headerdata['string'], 0, 1, 0, TRUE, $headerdata['align']);

  // print an ending header line
  $this
    ->SetLineStyle(array(
    'width' => 0.85 / $this
      ->getScaleFactor(),
    'cap' => 'butt',
    'join' => 'miter',
    'dash' => 0,
    'color' => array(
      0,
      0,
      0,
    ),
  ));
  $this
    ->SetY(1 + max($imgy['left'], $this
    ->GetY()));
  $this
    ->SetY(1 + max($imgy['right'], $this
    ->GetY()));
  if ($this
    ->getRTL()) {
    $this
      ->SetX($ormargins['right']);
  }
  else {
    $this
      ->SetX($ormargins['left']);
  }
  if (!$empty_header) {
    $this
      ->Cell(0, 0, '', 'T', 0, 'C');
  }
  $this
    ->SetTopMargin($this
    ->GetY() + 1);
}