-->

PrestaShop libraries replacement

2019-09-20 10:45发布

问题:

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?

回答1:

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