function views_pdf_plugin_display::execute in Views PDF 7
Same name and namespace in other branches
- 6 views_pdf_plugin_display.inc \views_pdf_plugin_display::execute()
- 7.3 views_pdf_plugin_display.inc \views_pdf_plugin_display::execute()
- 7.2 plugins/views_pdf_plugin_display.inc \views_pdf_plugin_display::execute()
This function executes the PDF display.
Overrides views_plugin_display_page::execute
File
- ./
views_pdf_plugin_display.inc, line 45 - 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') {
// Defines external configuration for TCPDF library
if (!defined('K_TCPDF_EXTERNAL_CONFIG')) {
$tcpdf_path = drupal_realpath(views_pdf_get_library('tcpdf'));
$cache_path = 'public://views_pdf_cache/';
file_prepare_directory($cache_path, FILE_CREATE_DIRECTORY);
global $base_url;
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
define('K_PATH_URL', $base_url);
define('K_PATH_FONTS', $tcpdf_path . '/fonts/');
define('K_PATH_CACHE', drupal_realpath($cache_path));
define('K_PATH_IMAGES', '');
define('K_BLANK_IMAGE', $tcpdf_path . '/images/_blank.png');
define('K_CELL_HEIGHT_RATIO', 1.25);
define('K_SMALL_RATIO', 2 / 3);
}
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'));
// Generall document layout
// Set default code
$this->view->pdf
->SetFont('');
// Add leading pages
$path = $this->view->pdf
->getTemplatePath($this
->get_option('leading_template'));
$this->view->pdf
->addPdfDocument($path);
// Set the default background template
$path = $this->view->pdf
->getTemplatePath($this
->get_option('template'));
$this->view->pdf
->setDefaultPageTemplate($path, 'main');
$this->view->pdf
->setViewsHeader($this->view->display_handler
->render_header(), $this->options['style_options']);
$footer = $this->view->display_handler
->render_footer();
$html = $this->view
->render($this->display->id);
$this->view->pdf
->setViewsFooter($footer, $this->options['style_options']);
// Add succeed pages
$path = $this->view->pdf
->getTemplatePath($this
->get_option('succeed_template'));
$this->view->pdf
->addPdfDocument($path);
if (!empty($html)) {
echo $html;
}
if (empty($path_to_store_pdf)) {
$path_to_store_pdf = $this->view
->get_title();
$this->view->pdf
->SetTitle($this->view
->get_title());
}
if (!preg_match('/\\.pdf$/', $path_to_store_pdf)) {
$path_to_store_pdf .= '.pdf';
}
ob_clean();
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);
}
}