Jump to content

Edit History

qu3nd1

qu3nd1

Okay, by analyzing how the tcpdf Output() function works, I found the perfect solution. We need to understand that destination "F" will only store the file without being able to send it to the browser properly, while "FI" can store and send online content to the browser (pdf file will be displayed in the same tab basically) , and "FD" can store and trigger a download of the file (in a modern browser this will usually open a new tab with the file displayed inside). I chose download.

PDF.php

<?php

class PDF extends PDFCore
{
    public function render($display = true)
    {
        if(in_array($this->template, [PDF::TEMPLATE_INVOICE, PDF::TEMPLATE_ORDER_SLIP]))
            return parent::render('FD');

        return parent::render($display);
    }
}

PDFGenerator.php

<?php

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

        $this->lastPage();

        if ($display === true) {
            $output = 'D';
        } elseif ($display === false) {
            $output = 'S';
        } elseif ($display == 'D') {
            $output = 'D';
        } elseif ($display == 'S') {
            $output = 'S';
        } elseif (in_array($display, ['F', 'FI', 'FD'])) {
            $output = $display;
            $filename = _PS_ROOT_DIR_.'/invoices/'.$filename;
        } else {
            $output = 'I';
        }

        return $this->Output($filename, $output);
    }
}

Everyone can modify this to suit their needs, but this is the more robust solution I've found. 😁

qu3nd1

qu3nd1

Okay, by analyzing how the tcpdf Output() function works, I found the perfect solution. We need to understand that destination "F" will only store the file without being able to send it to the browser properly, while "FI" can store and send online content to the browser (pdf file will be displayed in the same tab basically) , and "FD" can store and trigger a download of the file (in a modern browser this will usually open a new tab with the file displayed inside). I chose download.

PDF.php

<?php

class PDF extends PDFCore
{
    public function render($display = true)
    {
        if(in_array($this->template, [PDF::TEMPLATE_INVOICE, PDF::TEMPLATE_ORDER_SLIP]))
            parent::render('FD');

        parent::render($display);
    }
}

PDFGenerator.php

<?php

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

        $this->lastPage();

        if ($display === true) {
            $output = 'D';
        } elseif ($display === false) {
            $output = 'S';
        } elseif ($display == 'D') {
            $output = 'D';
        } elseif ($display == 'S') {
            $output = 'S';
        } elseif (in_array($display, ['F', 'FI', 'FD'])) {
            $output = $display;
            $filename = _PS_ROOT_DIR_.'/invoices/'.$filename;
        } else {
            $output = 'I';
        }

        return $this->Output($filename, $output);
    }
}

Everyone can modify this to suit their needs, but this is the more robust solution I've found. 😁

qu3nd1

qu3nd1

Okay, by analyzing how the tcpdf Output() function works, I found the perfect solution. We need to understand that destination "F" will only store the file without being able to send it to the browser properly, while "FI" can store and send online content to the browser (pdf file will be displayed in the same tab basically) , and 'FD' can store and trigger a download of the file (in a modern browser this will usually open a new tab with the file displayed inside). I chose download.

PDF.php

<?php

class PDF extends PDFCore
{
    public function render($display = true)
    {
        if(in_array($this->template, [PDF::TEMPLATE_INVOICE, PDF::TEMPLATE_ORDER_SLIP]))
            parent::render('FD');

        parent::render($display);
    }
}

PDFGenerator.php

<?php

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

        $this->lastPage();

        if ($display === true) {
            $output = 'D';
        } elseif ($display === false) {
            $output = 'S';
        } elseif ($display == 'D') {
            $output = 'D';
        } elseif ($display == 'S') {
            $output = 'S';
        } elseif (in_array($display, ['F', 'FI', 'FD'])) {
            $output = $display;
            $filename = _PS_ROOT_DIR_.'/invoices/'.$filename;
        } else {
            $output = 'I';
        }

        return $this->Output($filename, $output);
    }
}

Everyone can modify this to suit their needs, but this is the more robust solution I've found. 😁

×
×
  • Create New...