/** * Render HTML formatted string as a PDF * * @param string $ps_content A fully-formed HTML document to render as a PDF * @param array $pa_options Options include: * stream = Output the rendered PDF directly to the response [Default=false] * filename = The filename to set the PDF to when streams [Default=export_results.pdf] * * @return string The rendered PDF content * @seealso WLPlugPDFRendererPhantomJS::renderFile() */ public function render($ps_content, $pa_options = null) { file_put_contents($vs_content_path = caMakeGetFilePath("phantomjs", "html"), $ps_content); $vs_output_path = caMakeGetFilePath("phantomjs", "pdf"); exec($x = $this->ops_phantom_path . " " . __CA_LIB_DIR__ . "/core/Print/phantomjs/rasterise.js " . caEscapeShellArg($vs_content_path) . " " . caEscapeShellArg($vs_output_path) . " {$this->ops_page_size} {$this->ops_page_orientation} {$this->ops_margin_right} {$this->ops_margin_bottom} {$this->ops_margin_left}", $va_output, $vn_return); $vs_pdf_content = file_get_contents($vs_output_path); if (caGetOption('stream', $pa_options, false)) { header("Cache-Control: private"); header("Content-type: application/pdf"); header("Content-Disposition: attachment; filename=" . caGetOption('filename', $pa_options, 'output.pdf')); print $vs_pdf_content; } @unlink($vs_content_path); @unlink($vs_output_path); return $vs_pdf_content; }
/** * Render HTML formatted string as a PDF * * @param string $ps_content A fully-formed HTML document to render as a PDF * @param array $pa_options Options include: * stream = Output the rendered PDF directly to the response [Default=false] * filename = The filename to set the PDF to when streams [Default=output.pdf] * * @return string The rendered PDF content * @seealso wkhtmltopdf::renderFile() */ public function render($ps_content, $pa_options = null) { // Extract header and footer $vs_header = preg_match("/<!--BEGIN HEADER-->(.*)<!--END HEADER-->/s", $ps_content, $va_matches) ? $va_matches[1] : ''; $vs_footer = preg_match("/<!--BEGIN FOOTER-->(.*)<!--END FOOTER-->/s", $ps_content, $va_matches) ? $va_matches[1] : ''; $ps_content = preg_replace("/<!--BEGIN HEADER-->(.*)<!--END HEADER-->/s", "", $ps_content); $ps_content = preg_replace("/<!--BEGIN FOOTER-->(.*)<!--END FOOTER-->/s", "", $ps_content); file_put_contents($vs_content_path = caMakeGetFilePath("wkhtmltopdf", "html"), $ps_content); file_put_contents($vs_header_path = caMakeGetFilePath("wkhtmltopdf", "html"), $vs_header); file_put_contents($vs_footer_path = caMakeGetFilePath("wkhtmltopdf", "html"), $vs_footer); $vs_output_path = caMakeGetFilePath("wkhtmltopdf", "pdf"); exec($this->ops_wkhtmltopdf_path . " --disable-smart-shrinking --dpi 96 --encoding UTF-8 --margin-top {$this->ops_margin_top} --margin-bottom {$this->ops_margin_bottom} --margin-left {$this->ops_margin_left} --margin-right {$this->ops_margin_right} --page-size {$this->ops_page_size} --orientation {$this->ops_page_orientation} page " . caEscapeShellArg($vs_content_path) . " --header-html {$vs_header_path} --footer-html {$vs_footer_path} {$vs_output_path}", $va_output, $vn_return); $vs_pdf_content = file_get_contents($vs_output_path); if (caGetOption('stream', $pa_options, false)) { header("Cache-Control: private"); header("Content-type: application/pdf"); header("Content-Disposition: attachment; filename=" . caGetOption('filename', $pa_options, 'output.pdf')); print $vs_pdf_content; } @unlink($vs_content_path); @unlink($vs_header_path); @unlink($vs_footer_path); @unlink($vs_output_path); return $vs_pdf_content; }