定制Joomla PDF输出

定制Joomla PDF输出,pdf,joomla,Pdf,Joomla,在Joomla 1.5中,JDocumentPDF类的构造函数有一个数组参数来设置生成的PDF的一些参数 function __construct($options = array()) { parent::__construct($options); if (isset($options['margin-header'])) { $this->_margin_header = $options['margin-header']; } i

在Joomla 1.5中,JDocumentPDF类的构造函数有一个数组参数来设置生成的PDF的一些参数

function __construct($options = array()) {
    parent::__construct($options);

    if (isset($options['margin-header'])) {
        $this->_margin_header = $options['margin-header'];
    }

    if (isset($options['margin-footer'])) {
        $this->_margin_footer = $options['margin-footer'];
    }

    if (isset($options['margin-top'])) {
        $this->_margin_top = $options['margin-top'];
    }
    ...
}
_JFactory类的createDocument函数实例化JDocumentPDF对象,但不传递任何对生成PDF有用的选项:

function &_createDocument()     {

    ...

    $attributes = array (
        'charset'   => 'utf-8',
        'lineend'   => 'unix',
        'tab'       => '  ',
        'language'  => $lang->getTag(),
        'direction' => $lang->isRTL() ? 'rtl' : 'ltr'
    );

    $doc =& JDocument::getInstance($type, $attributes);
    return $doc;
}
因此,我不明白它是如何工作的,在哪里可以设置此选项页边距页眉、页边距页脚等?

来设置和获取JDocumentPDF的任何属性

您可以在对象上调用set和get函数。比如说

$obj = JFactory::getDocument();
$marginHeader  = $obj->get('_margin_header');
$obj->set('_margin_header', $value);
设置和获取JDocumentPDF的任何属性

您可以在对象上调用set和get函数。比如说

$obj = JFactory::getDocument();
$marginHeader  = $obj->get('_margin_header');
$obj->set('_margin_header', $value);

get和set将与joomla类的ll对象一起工作,joomla类由JObject继承。谢谢,它可以工作!顺便说一句,基于您的解决方案,它可以用php魔术方法解决。但是JDocument类是由Joomla定义的。在这种情况下,您需要对其进行扩展,或者需要对核心代码进行更改。如果所有这些东西在Joomla中都可用,为什么我们更喜欢黑客代码。get和set将与Joomla类的ll对象一起工作,Joomla类由JObject继承。谢谢,它可以工作!顺便说一句,基于您的解决方案,它可以用php魔术方法解决。但是JDocument类是由Joomla定义的。在这种情况下,您需要对其进行扩展,或者需要对核心代码进行更改。如果所有这些东西在Joomla都可用,我们为什么更喜欢黑客代码呢。