From 007590da6d2775e57419d544caa24da527dbf3ac Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 14 Jul 2016 12:34:43 -0400 Subject: [PATCH] CRM-17608 - Preserve formatting of output document Output document directly instead of going through phpWord --- CRM/Utils/PDF/Document.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/CRM/Utils/PDF/Document.php b/CRM/Utils/PDF/Document.php index 78d48126b4..e20ae65242 100644 --- a/CRM/Utils/PDF/Document.php +++ b/CRM/Utils/PDF/Document.php @@ -197,6 +197,8 @@ class CRM_Utils_PDF_Document { ); $dataMap = $ooxmlMap[$docType]; + + /* @var clsTbsZip $zip */ list($finalContent, $zip) = self::doc2Text($filePath, $docType, TRUE); // token-replaced document contents of each contact will be merged into final document @@ -216,21 +218,11 @@ class CRM_Utils_PDF_Document { $finalContent = str_replace($dataMap['endTag'], $content, $finalContent); } - //replace the loaded document file content located at $filePath with $finaContent + // Replace the loaded document file content located at $filePath with $finaContent $zip->FileReplace($dataMap['dataFile'], $finalContent, TBSZIP_STRING); - // get and path of civicrm upload directory and then construct the filepath of final document - $uploadDir = Civi::settings()->get('uploadDir'); - $absPath = Civi::paths()->getPath($uploadDir) . "CiviLetter.$docType"; - - // cleanup temporary document file created earlier if any - if (file_exists($absPath)) { - unlink($absPath); - } - // save the file document in civicrm upload directory, later used to download - $zip->Flush(TBSZIP_FILE, $absPath); - - self::printDoc($absPath, $docType, "CiviLetter.$docType"); + $fileName = pathinfo($filePath, PATHINFO_FILENAME) . '.' . $docType; + $zip->Flush(TBSZIP_DOWNLOAD, $fileName); } } -- 2.25.1