来源:[[http://trac.seagullproject.org/wiki/Integration/PDF/HTML_ToPDF]] ==== 集成HTML_ToPDF ==== === 概述 === HTML_ToPDF是用来动态将HTML页面转换成PDF格式输出的一个PHP类。 [[http://www.rustyparts.com/pdf.php]] 使用HTML_ToPDF将HTML转换成PDF非常容易 。所以可以使用Flexy创建相应的模板以达到相应的输出格式。 === 例子 === masterTemplate = 'reviewViewPdf.html'; // Create a unique filename for the resulting PDF $linkToPDFFull = $linkToPDF = tempnam(SGL_PATH . '/www/review', 'PDF-'); // Remove the temporary file it creates unlink($linkToPDFFull); // Give it an extension $linkToPDFFull .= '.pdf'; $linkToPDF .= '.pdf'; // Make it web accessible $linkToPDF = basename($linkToPDF); $output->itemDetails = SGL_Item::getItemDetail( $output->leadArticle['reviewItemId'], null, $language, true); $view = new SGL_HtmlSimpleView($output); $url = SGL_BASE_URL . '/review/' . $linkToPDF; // Send the class our HTML and the defaultDomain for images, css, etc. $pdf = new HTML_ToPDF($view->render(), ''); $pdf->setFooter('left', $this->conf['site']['name']); $pdf->setFooter('right', '$D'); // Could turn on debugging to see what exactly is happening // (commands being run, images being grabbed, etc.) //$pdf->setDebug(true); $result = $pdf->convert(); if (is_a($result, 'HTML_ToPDFException')) { SGL::raiseMsg('HTML to PDF error: ' . $result->getMessage()); } copy($result, $linkToPDFFull); unlink($result); if (file_exists($linkToPDFFull)) { header('Location: ' . $url); } }