/**
  * Method to download the pdf.
  *
  * @author KnowledgeTree Team
  * @access public
  */
 public function do_pdfdownload()
 {
     global $default;
     $iDocId = $this->oDocument->iId;
     // Check if pdf has already been created
     $dir = $default->pdfDirectory;
     $file = $dir . '/' . $iDocId . '.pdf';
     $mimetype = 'application/pdf';
     $size = filesize($file);
     // Set the filename
     $name = $this->oDocument->getFileName();
     $aName = explode('.', $name);
     array_pop($aName);
     $name = implode('.', $aName) . '.pdf';
     if (file_exists($file)) {
         if (KTUtil::download($file, $mimetype, $size, $name) === false) {
             $default->log->error('PDF Generator: PDF file could not be downloaded because it doesn\'t exist');
             $this->errorRedirectToMain(_kt('PDF file could not be downloaded because it doesn\'t exist'));
         }
         exit;
     }
     // If not - create one
     $converter = new pdfConverter();
     $converter->setDocument($this->oDocument);
     $res = $converter->processDocument();
     if (!$res) {
         $default->log->error('PDF Generator: PDF file could not be generated');
         $this->errorRedirectToMain(_kt('PDF file could not be generated, the file may be of an unsupported mime type.'));
         exit;
     }
     if (file_exists($file)) {
         if (KTUtil::download($file, $mimetype, $size, $name) === false) {
             $default->log->error('PDF Generator: PDF file could not be downloaded because it doesn\'t exist');
             $this->errorRedirectToMain(_kt('PDF file could not be downloaded because it doesn\'t exist'));
         }
         exit;
     }
     $this->errorRedirectToMain(_kt('PDF file could not be generated'));
     exit;
 }
 /**
  * Method to download the pdf.
  *
  * @author KnowledgeTree Team
  * @access public
  */
 public function do_pdfdownload()
 {
     global $default;
     $iDocId = $this->oDocument->iId;
     // Check if pdf has already been created
     $dir = $default->pdfDirectory;
     $file = $dir . '/' . $iDocId . '.pdf';
     $mimetype = 'application/pdf';
     $size = filesize($file);
     // Set the filename
     $name = $this->oDocument->getFileName();
     $aName = explode('.', $name);
     array_pop($aName);
     $name = implode('.', $aName) . '.pdf';
     if (file_exists($file)) {
         if (KTUtil::download($file, $mimetype, $size, $name) === false) {
             $default->log->error('PDF Generator: PDF file could not be downloaded because it doesn\'t exist');
             $this->errorRedirectToMain(_kt('PDF file could not be downloaded because it doesn\'t exist'));
         }
         exit;
     }
     // If not - create one
     $converter = new pdfConverter();
     $converter->setDocument($this->oDocument);
     $res = $converter->processDocument();
     if ($res !== true) {
         // please contact your System Administrator
         $default->log->error('PDF Generator: PDF file could not be generated');
         $this->errorRedirectToMain($res . ' ' . _kt('Please contact your System Administrator for assistance.'));
         exit;
     }
     if (file_exists($file)) {
         if (KTUtil::download($file, $mimetype, $size, $name) === false) {
             $default->log->error('PDF Generator: PDF file could not be downloaded because it doesn\'t exist');
             $this->errorRedirectToMain(_kt('PDF file could not be downloaded because it doesn\'t exist'));
         }
         exit;
     }
     // Check if this is a office 2007 doc
     $mime = $this->getMimeExtension();
     $o2007_types[] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
     $o2007_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
     $o2007_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
     if (in_array($mime, $o2007_types)) {
         $error = _kt('The document is an MS Office 2007 format. This may not be supported by your version of OpenOffice. Please contact your System Administrator for assistance');
         $default->log->error('PDF Generator: Document is an MS Office 2007 format. OpenOffice must be version 3.0 or higher to support this format. Please upgrade to the latest version.');
     } else {
         $error = _kt('PDF file could not be generated. The format may not be supported by your version of OpenOffice. Please contact your System Administrator for assistance');
         $default->log->error('PDF Generator: PDF file could not be generated. The format may not be supported by your version of OpenOffice. Please check that you have the latest version installed.');
     }
     $this->errorRedirectToMain($error);
     exit;
 }