You are here

class PdfExportMpdfProcessor in PDF Export 7

@file PDF Export: mPDF processor class.

Hierarchy

Expanded class hierarchy of PdfExportMpdfProcessor

1 string reference to 'PdfExportMpdfProcessor'
pdf_export_mpdf_pdf_export_processor_info in pdf_export_mpdf/pdf_export_mpdf.module
Implements hook_pdf_export_processor_info().

File

pdf_export_mpdf/includes/PdfExportMpdfProcessor.inc, line 7
PDF Export: mPDF processor class.

View source
class PdfExportMpdfProcessor implements PdfExportProcessorInterface {
  protected $library;

  /**
   * Initializes the mPDF plugin.
   */
  public function loadLibrary() {
    $library = libraries_load('mpdf');
    if (!$library['loaded']) {
      return FALSE;
    }
    $this->library = new mPDF('utf-8', 'A4');
    return TRUE;
  }

  /**
   * Defines base path for images.
   */
  public function setBasePath($base_path) {
    $this->library
      ->SetBasePath($base_path);
  }

  /**
   * Adds css styles to the pdf.
   *
   * @param string $styles
   *   CSS styles.
   */
  public function addCssStyles($styles) {
    $this->library
      ->WriteHTML($styles, 1);
  }

  /**
   * Sets the HTML to be exported.
   *
   * @param string $html
   *   Final HTML string to be exported.
   */
  public function setHTML($html) {
    $this->library
      ->WriteHTML($html, 2);
  }

  /**
   * Enable debugging for troubleshooting.
   */
  public function enableDebug() {
    $this->library->showImageErrors = TRUE;
    $this->library->debug = TRUE;
  }

  /**
   * Save generated file to the filesystem.
   *
   * @param string $filename
   *   The path where the pdf should be exported.
   *
   * @return bool
   *   TRUE if successfully exported. FALSE otherwise.
   */
  public function save($filename) {
    return $this->library
      ->Output($filename, 'F');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PdfExportMpdfProcessor::$library protected property
PdfExportMpdfProcessor::addCssStyles public function Adds css styles to the pdf. Overrides PdfExportProcessorInterface::addCssStyles
PdfExportMpdfProcessor::enableDebug public function Enable debugging for troubleshooting. Overrides PdfExportProcessorInterface::enableDebug
PdfExportMpdfProcessor::loadLibrary public function Initializes the mPDF plugin. Overrides PdfExportProcessorInterface::loadLibrary
PdfExportMpdfProcessor::save public function Save generated file to the filesystem. Overrides PdfExportProcessorInterface::save
PdfExportMpdfProcessor::setBasePath public function Defines base path for images. Overrides PdfExportProcessorInterface::setBasePath
PdfExportMpdfProcessor::setHTML public function Sets the HTML to be exported. Overrides PdfExportProcessorInterface::setHTML