且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PrestaShop库替换

更新时间:2023-02-22 15:27:46

我在其中创建的覆盖工具文件夹并且我把我们在这里找到的dompdf-master https://github.com/dompdf/dompdf 。。 p>

相反,我复制了PDFGenerator.php内的override / classes / pdf中,在classes / pdf中。



在PDFGenerator中.php添加:

  require_once('/../ override / tools / dompdf-master / dompdf / Dompdf.php') ; 
require_once(’/../ override / tools / dompdf-master / autoload.inc.php’);
include(’/../ override / tools / dompdf-master / dompdf / dompdf_config.inc.php’);
使用Dompdf\Dompdf;
使用Dompdf\Options;

课程变为:

 类PDFGenerator扩展DOMPDF 

取消render()函数并将其替换为:

 公共函数render($ filename,$ display = true)
{
if(empty( $ filename)){
抛出新的PrestaShopException('Missing filename。');
}

$ html = $ this-> header。$ this-> content。$ this->页脚;
// die($ html);

$ options = new Options();
$ options-> set('A4','potrait');
$ options-> set('enable_css_float',true);
$ options-> set('isHtml5ParserEnabled',true);

$ dompdf =新的DOMPDF($ options);
$ dompdf-> load_html($ html);

$ dompdf-> render();

$ dompdf-> stream($ filename);
}

然后我删除了cache / class_index.php


I use PrestaShop 1.6.1.4 and I want to change the library tcpdf with dompdf.

I use this form for creating invoices.

What are the best practices for a library exchange?

I created inside override the tools folder and I put us dompdf-master found here https://github.com/dompdf/dompdf.

Instead inside override/classes/pdf i copied PDFGenerator.php, there is in classes/pdf.

In PDFGenerator.php add:

require_once('/../override/tools/dompdf-master/dompdf/Dompdf.php');
require_once('/../override/tools/dompdf-master/autoload.inc.php');
include('/../override/tools/dompdf-master/dompdf/dompdf_config.inc.php');
use Dompdf\Dompdf;
use Dompdf\Options;

The class becomes:

class PDFGenerator extends DOMPDF

Eliminates the render() function and replace it with:

public function render($filename, $display = true)
{
    if (empty($filename)) {
        throw new PrestaShopException('Missing filename.');
    }

    $html = $this->header.$this->content.$this->footer;
    //die($html);    

    $options = new Options();
    $options->set('A4','potrait');
    $options->set('enable_css_float',true);
    $options->set('isHtml5ParserEnabled', true);

    $dompdf = new DOMPDF($options);
    $dompdf->load_html($html);

    $dompdf->render();

    $dompdf->stream($filename);
}

Then i deleted cache/class_index.php