From 2e0f0ed546609391fecbee7391b638fb6e6ae633 Mon Sep 17 00:00:00 2001 From: Lisa Marie Maginnis Date: Mon, 21 Sep 2015 13:25:15 -0400 Subject: [PATCH] Hax for pdflatex --- CRM/Utils/PDF/Utils.php | 114 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index 72d4880563..931c721b2a 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -32,8 +32,119 @@ * $Id$ * */ + class CRM_Utils_PDF_Utils { + static function enqueuePDF($pdf) { + + + $fname = time().'_lp.pdf'; + file_put_contents('/tmp/'.$fname, $pdf); + header('Location: /civicrm/lp-setup?file='.$fname); + exit; + + } + + + 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{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} +\setDefaultTransitions{\fontspec{CMU Serif}}{} +\setTransitionsForLatin{\fontspec{CMU Serif}}{} +\setTransitionsForArabics{\fontspec{Droid Sans Arabic}}{} +\setTransitionsForCJK{\fontspec{WenQuanYi Zen Hei}}{} +\setTransitionsForDiacritics{\fontspec{Droid Sans Arabic}}{} +\setTransitionTo{Hebrew}{\fontspec{David CLM}} +\setmainfont{CMU Serif} + +\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/drupal-7.27/sites/all/modules/civicrm/sigjohns.pdf} + \\\\ + + \ifx\@empty\fromsig + \fromname + \else \fromsig \fi\strut} + \par} +\medskipamount=\parskip + +%% This line might be necessary, but it was not able to find utf8.def on my +%% machine. +%% \usepackage[utf8x]{inputenc} +\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 . '"'); + echo $pdf; +// CRM_Utils_PDF_Utils::enqueuePDF($pdf); + + } + } + static function html2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL) { if (is_array($text)) { $pages = &$text; @@ -132,6 +243,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; @@ -140,6 +252,8 @@ class CRM_Utils_PDF_Utils { header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); echo $pdf; + //CRM_Utils_PDF_Utils::enqueuePDF($pdf); + } } -- 2.25.1