Exemple #1
0
 /**
  * Builds the PDF delivery for the given faq.
  * 
  * @param  integer $currentCategory The category under which we want the PDF to be created.
  * @param  string  $pdfFile         The path to the PDF file. Optional, default: pdf/<faq_id>.pdf.
  * @return mixed
  */
 public function buildPDFFile($currentCategory, $pdfFile = null)
 {
     global $PMF_LANG;
     // Sanity check: stop here if getRecord() has not been called yet
     if (empty($this->faqRecord)) {
         return false;
     }
     $faqconfig = PMF_Configuration::getInstance();
     $category = new PMF_Category();
     // Default filename: pdf/<faq_id>.pdf
     if (empty($pdfFile)) {
         $pdfFile = 'pdf/' . $this->faqRecord['id'] . '.pdf';
     }
     // Cleanup any file
     if (file_exists($pdfFile)) {
         @unlink($pdfFile);
     }
     $pdf = new PMF_Export_Pdf($currentCategory, $this->faqRecord['title'], $category->categoryName);
     $pdf->faq = $this->faqRecord;
     // Start building PDF...
     $pdf->Open();
     // Set any item
     $pdf->SetTitle($this->faqRecord['title']);
     $pdf->SetCreator($faqconfig->get('main.titleFAQ') . ' - powered by phpMyFAQ ' . $faqconfig->get('main.currentVersion'));
     $pdf->AliasNbPages();
     $pdf->AddPage();
     $pdf->SetFont('dejavusans', '', 12);
     $pdf->SetDisplayMode('real');
     $pdf->Ln();
     $pdf->WriteHTML(str_replace('../', '', $this->faqRecord['content']), true);
     $pdf->Ln();
     $pdf->Ln();
     $pdf->SetFont('dejavusans', '', 11);
     $pdf->Write(5, $PMF_LANG['ad_entry_solution_id'] . ': #' . $this->faqRecord['solution_id']);
     $pdf->SetAuthor($this->faqRecord['author']);
     $pdf->Ln();
     $pdf->Write(5, $PMF_LANG['msgAuthor'] . ': ' . $this->faqRecord['author']);
     $pdf->Ln();
     $pdf->Write(5, $PMF_LANG['msgLastUpdateArticle'] . $this->faqRecord['date']);
     // Build it
     $pdf->Output($pdfFile);
     // Done?
     if (!file_exists($pdfFile)) {
         return false;
     }
     return $pdfFile;
 }