Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

php - PrestaShop libraries replacement

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 DompdfDompdf;
use DompdfOptions;

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...