mPDF Manual – mPDF functions

SetBasePath()

(mPDF ≥ 1.0)

SetBasePath – Specifies a base URL for mPDF to interpret relative URLs

Description

void SetBasePath ( string $url )

Specifies that mPDF should interpret any URLs in the HTML code relative to this $url. Otherwise relative paths will be based on the current script. This is important for hyperlinks, external stylesheets, and images.

Parameters

$url

A full URL should be provided, but the following will all work:

  • http://www.mydomain.com
  • http://www.mydomain.com/index.php
  • http://www.mydomain.com/path/

Examples

<?php
$mpdf = new \Mpdf\Mpdf();

$url = "http://www.php.net/manual/en/function.iconv.php";
$html = file_get_contents($url);

$mpdf->setBasePath($url);

// Now any relative paths e.g. <img src="../picture.jpg" /> will be parsed relative to
// a base path of "http://www.php.net/manual/en/"
$mpdf->WriteHTML($html);
$mpdf->Output();

Fork me on GitHub