/** * 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; }
/** * Returns the PDF export * * @param integer $nCatid Number of categories * @param boolean $bDownwards Downwards * @param string $lang Language * * @return string */ public static function getPDFExport($nCatid = 0, $bDownwards = true, $lang = "") { $tree = new PMF_Category(); $arrRubrik = array(); $arrThema = array(); $arrContent = array(); $arrAuthor = array(); $arrDatum = array(); // Get Faq Data $oFaq = new PMF_Faq(); $faqs = $oFaq->get(FAQ_QUERY_TYPE_EXPORT_PDF, $nCatid, $bDownwards, $lang); if (count($faqs) > 0) { $i = 0; // Get the data foreach ($faqs as $faq) { $arrRubrik[$i] = $faq['category_id']; $arrThema[$i] = $faq['topic']; $arrContent[$i] = $faq['content']; $arrAuthor[$i] = $faq['author_name']; $arrDatum[$i] = $faq['lastmodified']; $i++; } // Start composing PDF $pdf = new PMF_Export_Pdf(); $pdf->enableBookmarks = true; $pdf->isFullExport = true; $pdf->Open(); $pdf->AliasNbPages(); $pdf->SetDisplayMode('real'); // Create the PDF foreach ($arrContent as $key => $value) { $pdf->category = $arrRubrik[$key]; $pdf->thema = $arrThema[$key]; $pdf->categories = $tree->categoryName; $date = $arrDatum[$key]; $author = $arrAuthor[$key]; $pdf->AddPage(); $pdf->SetFont("Arial", "", 12); $pdf->WriteHTML($value); } return $pdf->Output('', 'S'); } }