隐藏自定义pdf Prestashop中的页眉和页脚



我在Prestashop 1.7.4.1的模块中制作了打印自定义pdf的方法。一切正常,但它打印带有商店徽标和页脚的页眉,并在每页上提供有关电子发票的信息。如何隐藏我的模板采用打印页面的所有大小的它们?

我试图从 tcpdf 示例添加到我的 pdf 目标代码中,但似乎我没有在 presta 中使用 TCPDF:

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

这是我的班级:

class HTMLTemplateCustomPdf extends HTMLTemplate
{
public $custom_model;
public function __construct($custom_object, $smarty)
{
$this->custom_model = $custom_object;
$this->smarty = $smarty;
}
/**
* Returns the template's HTML content
* @return string HTML content
*/
public function getContent()
{
//here I get content
return $this->smarty->fetch(_PS_MODULE_DIR_ . 'ps_first_module/views/templates/hook/pdf.tpl');
}
/**
* Returns the template filename
* @return string filename
*/
public function getFilename()
{
return 'custom_pdf.pdf';
}
/**
* Returns the template filename when using bulk rendering
* @return string filename
*/
public function getBulkFilename()
{
return 'custom_pdf.pdf';
}

这是我创建pdf对象的地方:

if (Tools::isSubmit('print')) {
if (Shop::getContext() != Shop::CONTEXT_GROUP && Shop::getContext() != Shop::CONTEXT_ALL) {
require_once _PS_MODULE_DIR_ . 'ps_first_module/HTMLTemplateCustomPdf.php';
$orientation = 'L';
$pdf = new PDF($custom_object, 'CustomPdf', Context::getContext()->smarty, $orientation);
$pdf->render();
}
}

编辑: 这是我的PDFGenerator.php覆盖。我应该把它放在root/override/classes/pdf还是my_module/override/classes/pdf中?

<?php
class PDFGenerator extends PDFGeneratorCore
{
/**
* @param bool $use_cache
* @param string $orientation
*/
public function __construct($use_cache = false, $orientation = 'L')
{
parent::__construct($orientation, 'mm', 'A4', true, 'UTF-8', $use_cache, false);
$this->setRTL(Context::getContext()->language->is_rtl);
}
/**
* Write a PDF page
*/
public function writePage()
{
if(!$this->header){
$this->SetHeaderMargin(0);
}
else{
$this->SetHeaderMargin(5);
}
if(!$this->footer){
$this->SetFooterMargin(0);
}
else{
$this->SetFooterMargin(21);
}
$this->setMargins(10, 10, 10);
$this->AddPage();
$this->writeHTML($this->content, true, false, true, false, '');
}
}

我在 1.7.2 版中尝试过,文件属性提到生产者:TCPDF 6.2.12 (http://www.tcpdf.org(。此外,函数 render(( 中的 Pdf 类为:

$this->pdf_renderer->createHeader($template->getHeader());
$this->pdf_renderer->createFooter($template->getFooter());

因此,最好的方法是您的类 HTMLTemplateCustomPdf 包含函数 getHeader(( 和 getFooter(( 以返回 false(或空(,否则它将使用 HTMLTemplateCore 中的函数。

在 PDFGenerator 的覆盖中,您可以执行以下操作:

public function writePage()
{
if(!$this->header){
$this->SetHeaderMargin(0);
}
else{
$this->SetHeaderMargin(5);
}
if(!$this->footer){
$this->SetFooterMargin(0);
}
else{
$this->SetFooterMargin(21);
}
$this->setMargins(10, 40, 10);
$this->AddPage();
$this->writeHTML($this->content, true, false, true, false, '');
}

如果需要,您还可以在$this->setMargins(10, 40, 10(中设置不同的边距;

最新更新