1

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.

LF00
  • 27,015
  • 29
  • 156
  • 295

2 Answers2

1

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.

Finwe
  • 6,372
  • 2
  • 29
  • 44
  • The question is about how to use `Output('filename.pdf', \Mpdf\Output\Destination::INLINE);` in `Mpdf v6.1.4`. – LF00 Nov 24 '19 at 00:27
  • No, the question was "How can i to perform the mPDF output function to show the pdf inline browser in mPDF v.6.1.4 ?", Which I answered. Sure, I could have been even more verbose, I edited the answer with a code example. – Finwe Nov 24 '19 at 21:46
  • i had ran this code brother but still downloaded the pdf instead of showing the pdf inline browser. – 01_Secret.Lubis_10 Nov 30 '19 at 13:03
  • What is your browser? Can you display PDFs inline from another sources? Do you set HTTP headers elsewhere in the code? – Finwe Dec 01 '19 at 18:42
  • i am using Chrome x78 and Firefo x68. Btw now whenever i want to show PDF inline browser. it would be downloaded instead of showing it in browser. Also i have set HTTP headers on top of my code. How can i show the PDF inline of Browser hmm. so that the user can see it content before downloading the PDF file. – 01_Secret.Lubis_10 Dec 07 '19 at 06:53
  • I meant Chrome v78 and Firefox v68. – 01_Secret.Lubis_10 Dec 08 '19 at 09:51
  • Do not set http headers yourself. You're probably overriding headers set my mPDF. – Finwe Dec 08 '19 at 10:00
  • I am sorry, what do you mean about "... overriding headers set ..." sir ? – 01_Secret.Lubis_10 Dec 29 '19 at 01:00
0

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';
}
LF00
  • 27,015
  • 29
  • 156
  • 295
  • you have given the good relevant source code brother, but unfortunately the pdf still download the file instead of showing inline browser brother. – 01_Secret.Lubis_10 Nov 30 '19 at 13:22
  • If you want to view it, you need to add `Content-Type: application/pdf` to header. – LF00 Dec 01 '19 at 04:20
  • I have added `header("Content-Type: application/pdf");` right after `include "config.php";` but still download the file. Do you have any solution brother ? – 01_Secret.Lubis_10 Dec 01 '19 at 10:29