You are here

function views_pdf_plugin_display::execute in Views PDF 6

Same name and namespace in other branches
  1. 7.3 views_pdf_plugin_display.inc \views_pdf_plugin_display::execute()
  2. 7 views_pdf_plugin_display.inc \views_pdf_plugin_display::execute()
  3. 7.2 plugins/views_pdf_plugin_display.inc \views_pdf_plugin_display::execute()

This function executes the PDF display.

File

./views_pdf_plugin_display.inc, line 61
PDF display plugin.

Class

views_pdf_plugin_display
This class contains all the functionality of the PDF display.

Code

function execute($path_to_store_pdf = '', $destination = 'I') {
  if ($this
    ->get_option('default_page_format') == 'custom') {
    if (preg_match('/([0-9]+)x([0-9]+)/', $this
      ->get_option('default_page_format_custom'), $result)) {
      $format[0] = $result[1];

      // width
      $format[1] = $result[2];

      // height
    }
    else {
      $format = 'A4';
    }
  }
  else {
    $format = $this
      ->get_option('default_page_format');
  }
  $orientation = $this
    ->get_option('default_page_orientation');

  // P or L
  $unit = $this
    ->get_option('unit');
  $this->view->pdf = views_pdf_get_new_pdf_instance($orientation, $unit, $format);

  // Set margins: top, left, right
  $this->view->pdf
    ->SetMargins($this
    ->get_option('margin_left'), $this
    ->get_option('margin_top'), $this
    ->get_option('margin_right'), TRUE);

  // Set auto page break: margin bottom:
  $this->view->pdf
    ->SetAutoPageBreak(TRUE, $this
    ->get_option('margin_bottom'));
  $this->view->pdf
    ->setDefaultFontSize($this
    ->get_option('default_font_size'));
  $this->view->pdf
    ->setDefaultFontFamily($this
    ->get_option('default_font_family'));
  $this->view->pdf
    ->setDefaultFontStyle($this
    ->get_option('default_font_style'));
  $this->view->pdf
    ->setDefaultTextAlign($this
    ->get_option('default_text_align'));
  $this->view->pdf
    ->setDefaultFontColor($this
    ->get_option('default_font_color'));
  $html = $this->view
    ->render($this->display->id);
  if (!empty($html)) {
    echo $html;
  }
  if (empty($path_to_store_pdf)) {
    $path_to_store_pdf = $this->view->name;
  }
  if (!preg_match('/\\.pdf$/', $path_to_store_pdf)) {
    $path_to_store_pdf .= '.pdf';
  }
  if ($destination == 'I') {
    echo $this->view->pdf
      ->Output($path_to_store_pdf, $destination);
    exit;
  }
  else {
    return $this->view->pdf
      ->Output($path_to_store_pdf, $destination);
  }
}