You are here

public function W2PDF::Header in Webform2PDF 7.4

Same name and namespace in other branches
  1. 6.2 webform2pdf.class.inc \W2PDF::Header()
  2. 6 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 117

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 ($headerdata['background']) {

    // get the current page break margin
    $bMargin = $this
      ->getBreakMargin();

    // get current auto-page-break mode
    $auto_page_break = $this->AutoPageBreak;

    // disable auto-page-break
    $this
      ->SetAutoPageBreak(false, 0);

    //Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array())
    $this
      ->Image($headerdata['background'], 0, 0, $this->w, $this->h, '', '', '', false, 300, '', false, false, 0);

    // restore auto-page-break status
    $this
      ->SetAutoPageBreak($auto_page_break, $bMargin);

    // set the starting point for the page content
    $this
      ->setPageMark();
  }
  if (!empty($headerdata['logo']['left']) && !empty($headerdata['logo_size']['left']['w'])) {
    if ($headerdata['logo']['left'] and $headerdata['logo']['left'] != K_BLANK_IMAGE) {
      $this
        ->Image($headerdata['logo']['left'], $this
        ->GetX(), $this
        ->getHeaderMargin(), $headerdata['logo_size']['left']['w']);
      $imgy['left'] = $this
        ->getImageRBY();
      $empty_header = 0;
    }
  }
  if ($headerdata['logo']['right'] and $headerdata['logo']['right'] != K_BLANK_IMAGE) {
    $this
      ->Image($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']['right']['w'] * 1.1;
    if (!empty($headerdata['logo']['left']) && !empty($headerdata['logo_size']['left']['w'])) {
      $header_w -= $headerdata['logo_size']['left']['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);
}