2

With mpdf, the following outputs the PDF inline to the browser:

$mpdf->Output();

How can I simply get the full URL of the created file? For example:

// http://example.com/tmp/file.pdf
$url = $mpdf->getURL();
Henrik Petterson
  • 6,862
  • 20
  • 71
  • 155

1 Answers1

2

When outputting the file to the browser, the output file name is the file name of your script, no physical PDF file is being created and saved anywhere.

Therefore you could use something like

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

as answered in this QA.

Note that this cannot be used when you rely on HTTP POST method to generate the PDF.


If you need to save and provide static pdf file for later download, use F (or helper constant \Mpdf\Output\Destination::FILE in mPDF 7.x) output mode with path to desired file in the Output method:

$filename = __DIR__ . '/download.pdf';
$mpdf->Output($filename, 'F');

You then have to create the URL to the file yourself as mPDF does not know anything (or care) about your domain, document root and path to the file-to-be-downloaded.

Also see documentation on the Output method.

Finwe
  • 6,372
  • 2
  • 29
  • 44
  • 1
    Are you saying that no PDF file is actually generated on the server? I need to send the PDF file through a different script via the full URL; is this possible using *mpdf*? Thanks for the response. – Henrik Petterson Mar 13 '18 at 18:57
  • Updated the answer. – Finwe Mar 14 '18 at 07:43
  • Maybe this should be a feature request. It would be good to know whether if the output was successful, something like `$boolean = $mpdf->Output($filename, 'F');` with true and false. – Henrik Petterson Mar 14 '18 at 11:59
  • If you don't get an error/exception from the Output method, the output was successful. – Finwe Mar 14 '18 at 13:41
  • On this page: https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html You are missing a `>` in `'fontdata' = [`... Just bringing it to your attention. Thanks! – Henrik Petterson Mar 16 '18 at 13:07
  • @HenrikPetterson please, do not pollute comments here with off-topic additions. There is a dedicated issue section for the documentation. https://github.com/mpdf/mpdf.github.io/issues – Finwe Mar 17 '18 at 07:25