CRM-17608 - Preserve formatting of output document
authorColeman Watts <coleman@civicrm.org>
Thu, 14 Jul 2016 16:34:43 +0000 (12:34 -0400)
committerdeb.monish <monish.deb@webaccessglobal.com>
Thu, 14 Jul 2016 18:05:43 +0000 (23:35 +0530)
Output document directly instead of going through phpWord

CRM/Utils/PDF/Document.php

index 78d48126b450ad37b41e9e6fb405e855762ab5d8..e20ae652422d70f3cd80e5e0cebf99964fa669cf 100644 (file)
@@ -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);
   }
 
 }