How to use Output('filename.pdf', \Mpdf\Output\Destination::INLINE); in mPDF v.6.1.4?

2.8k Views Asked by At

I have an issue when calling output function using v.6.1.4. Since i've ever tried to use Output('filename.pdf', \Mpdf\Output\Destination::INLINE); function in mPDF v.7.x so i tried this format function in mPDF v.6.1.4 (just changed "\Mpdf.." to "\mPDF..") because i am working with company that's using php 5 even older, and then i get this error:

Fatal error: Class 'mPDF\Output\Destination' not found.

How can i to perform the mPDF output function to show the pdf inline browser in mPDF v.6.1.4 ?

Thanks in Advance Brothers/Sisters.

2

There are 2 best solutions below

3
LF-DevJourney On

You cannot use \Mpdf\Output\Destination::INLINE in mPDF v.6.1.4, for class \Mpdf\Output\Destination is not defined in mPDF v.6.1.4. But you can use I instead of \Mpdf\Output\Destination::INLINE.

Class 'mPDF\Output\Destination is defined since mPdf v7.0.


To make it more clear, the relevant source code. Here is the source code, and there is no /Output/Destination.php in this version. https://raw.githubusercontent.com/mpdf/mpdf/v6.1.4/mpdf.php

function Output($name = '', $dest = '')
{

    ...
    if (is_bool($dest))
        $dest = $dest ? 'D' : 'F';
    $dest = strtoupper($dest);
    if ($dest == '') {
        if ($name == '') {
            $name = 'mpdf.pdf';
            $dest = 'I';
        } else {
            $dest = 'F';
        }
    }
    ...
}

Here is the source code of v7.0.0, and Output/Destination.php is added. https://raw.githubusercontent.com/mpdf/mpdf/v7.0.0/src/Mpdf.php

function Output($name = '', $dest = '')
{

    ...
    if (is_bool($dest)) {
        $dest = $dest ? Destination::DOWNLOAD : Destination::FILE;
    }

    $dest = strtoupper($dest);
    if (empty($dest)) {
        if (empty($name)) {
            $name = 'mpdf.pdf';
            $dest = Destination::INLINE;
        } else {
            $dest = Destination::FILE;
        }
    }
    ...
}

https://github.com/mpdf/mpdf/blob/v7.0.0/src/Output/Destination.php

<?php
namespace Mpdf\Output;
class Destination
{
    const FILE = 'F';
    const DOWNLOAD = 'D';
    const STRING_RETURN = 'S';
    const INLINE = 'I';
}
8
Finwe On

Use a string I as a second parameter, that means "inline".

$mpdf->Output('filename.pdf', 'I');

See the actual string values of the Output constants introduced in mPDF 7: https://github.com/mpdf/mpdf/blob/development/src/Output/Destination.php

The Mpdf::Output documentation page now also shows the actual values of helper Mpdf\Output\Destination class constants.