You are here

class FrxMPDF in Forena Reports 7.4

Same name and namespace in other branches
  1. 7.3 docformats/FrxMPDF.inc \FrxMPDF

@file FrxMPDF.inc PDF document via MPDF Library @author davidmetzler

Hierarchy

Expanded class hierarchy of FrxMPDF

1 string reference to 'FrxMPDF'
forena_pdf_configure in ./forena_pdf.module
Implementation of configuration form.

File

docformats/FrxMPDF.inc, line 8
FrxMPDF.inc PDF document via MPDF Library @author davidmetzler

View source
class FrxMPDF extends FrxDocument {
  private $p;
  public function __construct() {
    $tmp = file_directory_temp();

    // To do - use config variable of path to mpdf libs
    if (!file_exists("{$tmp}/mpdf")) {
      mkdir("{$tmp}/mpdf");
    }
    define('_MPDF_PATH', 'sites/all/libraries/mpdf/');
    define("_MPDF_TEMP_PATH", "{$tmp}/mpdf/");
    include_once 'sites/all/libraries/mpdf/mpdf.php';
    $this->content_type = 'application/pdf';
  }
  public function header($r, $print = TRUE) {
    $r->html = '';
  }
  public function render($r, $format, $options = array()) {

    // To Do
    // The option switch off links on PDF will bee good here too
    $disable_links = variable_get('forena_pdf_disable_links', TRUE);
    $skin_data = Frx::Data()
      ->getContext('skin');
    $page_data = isset($skin_data['mpdf']['page']) ? $skin_data['mpdf']['page'] : array(
      'orientation' => 'P',
    );
    $html = $r->html;
    if ($disable_links) {
      $html = preg_replace('/<a href=\\"(.*?)\\">(.*?)<\\/a>/', "\\2", $html);
    }
    $mpdf = new mPDF('UTF-8');
    $mpdf
      ->AddPageByArray($page_data);
    $output = '<html><head>';
    $output .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
    $css = '';
    foreach (Frx::Skin()->stylesheets as $type => $sheets) {
      foreach ($sheets as $sheet) {
        switch ($type) {
          case 'all':
          case 'print':
          case 'screen':
          case 'pdf':
            if (strpos($sheet, 'http:') === 0 || strpos($sheet, 'https:') === 0) {
              $output .= "    <link rel='stylesheet' type='text/css' href='{$sheet}'> \n";
            }
            else {
              $css .= file_get_contents($sheet);
            }

            //echo $sheet;
            break;
        }
      }
    }
    if (@$options['css'] || isset($r->rpt_xml->head->style)) {
      $output .= '<style type="text/css">';
      $output .= $css;
      if (isset($r->rpt_xml->head->style)) {
        $sheet = (string) $r->rpt_xml->head->style;
        $output .= $sheet;
      }
      $output .= '</style>';
    }
    $output .= '<title>' . $r->title . "</title></head><body class='forena-report {$link_class}'><h1>" . $r->title . '</h1>' . $html;
    $output .= '</body></html>';
    $mpdf
      ->WriteHTML($output);

    // $pdf = $mpdf->Output('', 'S');
    $filename = basename($_GET['q']);
    $pdf = $mpdf
      ->Output($filename, 'I');
    return $pdf;
  }
  public function output(&$output) {
    $http_headers = array(
      'Pragma' => 'no-cache',
      'Expires' => '0',
      'Cache-Control' => 'no-cache, must-revalidate',
      'Cache-Control' => 'private',
      'Content-Transfer-Encoding' => 'binary',
      'Content-Type' => 'application/pdf',
    );
    foreach ($http_headers as $name => $value) {
      $value = preg_replace('/\\r?\\n(?!\\t| )/', '', $value);
      drupal_add_http_header($name, $value);
    }
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrxDocument::$allowDirectOutput public property
FrxDocument::$charset public property
FrxDocument::$content_type public property
FrxDocument::$format public property
FrxDocument::$print public property
FrxDocument::check_markup public function Wrapper function for check output to default the right type.
FrxDocument::convertCharset public function
FrxDocument::loadCSSFiles public function
FrxMPDF::$p private property
FrxMPDF::header public function Overrides FrxDocument::header
FrxMPDF::output public function Overrides FrxDocument::output
FrxMPDF::render public function Overrides FrxDocument::render
FrxMPDF::__construct public function