X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=CRM%2FUtils%2FPDF%2FUtils.php;h=9353ea2ba397b9f6f7e45912fdcea8261973778b;hb=062653fae82e9802d9473bec96e0f2603384acaf;hp=014c2d846e40cef2e75adf58bcb0b7abd8bc9312;hpb=e24b39feb385f4254919f9e6aa6d174967d6102f;p=civicrm-core.git diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index 014c2d846e..9353ea2ba3 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -18,8 +18,115 @@ use Dompdf\Options; * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing */ + class CRM_Utils_PDF_Utils { + public static function enqueuePDF($pdf) { + + $fname = time().'_lp.pdf'; + file_put_contents('/tmp/'.$fname, $pdf); + header('Location: /civicrm/lp-setup?file='.$fname); + exit; + + } + + public static function latex2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL) { + /* FIXME: get $paper_size, $orientation, $margins */ + + if (is_array($text)) { + $pages = &$text; + } + else { + $pages = array($text); + } + + $head='\documentclass[12pt]{letter} +\usepackage{url} +\usepackage{ucs} +\usepackage{array} +\usepackage{graphicx} +\usepackage[T1]{fontenc} +\usepackage{fullpage} +\usepackage{fontspec,xunicode} +%% VERY IMPORTANT. Configures supported languages and fonts to use for each one. +\usepackage[Latin, Hebrew, Arabics, CJK, Diacritics]{ucharclasses} +\newfontfamily{\normalfont}[Ligatures=TeX]{FreeSerif} +\newfontfamily{\cjkfont}{WenQuanYi Zen Hei} +\setDefaultTransitions{\normalfont}{} +\setTransitionsForLatin{\normalfont}{} +\setTransitionsForArabics{\normalfont}{} +\setTransitionsForCJK{\cjkfont}{} +\setTransitionsForDiacritics{\normalfont}{} +\setTransitionTo{Hebrew}{\normalfont} +\setmainfont{FreeSerif} + +\newcommand{\fsfclosing}[1]{\par\nobreak\vspace{\parskip} + \stopbreaks + \noindent + \ifx\@empty\fromaddress\else + \hspace*{\longindentation}\fi + \parbox{\indentedwidth}{\raggedright + \ignorespaces #1\\\\[1\medskipamount] + \hspace*{-0.25in}\includegraphics[scale=1.0]{/var/www/html/sites/all/modules/civicrm/sigjohns.pdf} + \\\\ + + \ifx\@empty\fromsig + \fromname + \else \fromsig \fi\strut} + \par} +\medskipamount=\parskip + +\pagestyle{empty} +\tolerance=8000 +\address{\vspace{0.05in}} +\signature{John Sullivan \\\\ Executive Director} +\usepackage[ +top = 1.5in, +bottom = 1.25in, +left = 1.0in, +right = 1.0in]{geometry} +\begin{document} +'; + $footer=' +\end{document}'; + + $latex = $head; + foreach ($pages as $page) { + $latex.=$page; + } + $latex.=$footer; + + $descriptorspec = array( + 0 => array("pipe", "r"), + 1 => array("pipe", "w") + ); + + + + $process = proc_open("/usr/local/bin/pdflatex_wrapper.sh", $descriptorspec, $pipes); + + + if (is_resource($process)) { + fwrite($pipes[0], $latex); + fclose($pipes[0]); + + $pdf = stream_get_contents($pipes[1]); + fclose($pipes[1]); + } else { + CRM_Core_Error::debug_log_message("ERROR creating PDF. Check /tmp/pdflatex_*"); + } + + if ($output) { + return $pdf; + } + else { + header('Content-Type: application/pdf'); + header('Content-Disposition: attachment; filename="' . $fileName . '"'); + CRM_Utils_PDF_Utils::enqueuePDF($pdf); + + } + } + /** * @param array $text * List of HTML snippets. @@ -221,6 +328,7 @@ class CRM_Utils_PDF_Utils { $snappy->setOption("margin-right", $margins[2] . $margins[0]); $snappy->setOption("margin-bottom", $margins[3] . $margins[0]); $snappy->setOption("margin-left", $margins[4] . $margins[0]); + $html = preg_replace('/{ }/', ' ', $html); $pdf = $snappy->getOutputFromHtml($html); if ($output) { return $pdf; @@ -228,7 +336,8 @@ class CRM_Utils_PDF_Utils { else { CRM_Utils_System::setHttpHeader('Content-Type', 'application/pdf'); CRM_Utils_System::setHttpHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"'); - echo $pdf; + CRM_Utils_PDF_Utils::enqueuePDF($pdf); + } }