在Joomla! 1.5下,JDocuemntPDF可以简单实现PDF文件的生成。例如,我们给一个组件添加PDF,只要在视图目录下,添加一个view.pdf.php 就可以生成相应的PDF文件。简单的代码示例如下:
<?php
jimport( 'joomla.application.component.view');
class TestViewTest extends JView
{
function display($tpl = null)
{
global $mainframe;
$document = &JFactory::getDocument();
// set document information
$document->setTitle('this is title');
$document->setName('this is name');
$document->setDescription('this is description');
$document->setMetaData('keywords', 'this is key word');
// prepare header lines
$document->setHeader('this is header line');
echo 'this is content';
}
}
?>
现在你就可以在浏览器中访问这个PDF文件了,路径是http://yourdomain.com/index.php?option=com_test&view=test&format=pdf
就这么简单,快点试试吧。