1

I installed mpdf successfully via composer.

Here is my PHP code:

require_once __DIR__ . '/vendor/autoload.php';
$mpdf=new \Mpdf\Mpdf();
$mpdf->WriteHTML("<h1>test</h1>");
$file='abcd.pdf';
$mpdf->output($file,'I');

PDF won't generate. I tried in Chrome and Firefox. The location of autoload.php is correct. I tried D, F and S as well, as the second argument for $mpdf->output, none worked.

3 Answers 3

1

your code actually works, please double check your php version and note that mpdf is compatible only with PHP ≥ 5.6.0 and < 7.4.0.

https://mpdf.github.io/about-mpdf/requirements-v7.html

Sign up to request clarification or add additional context in comments.

Comments

0
require_once __DIR__ . '/vendor/autoload.php';
$mpdf=new \Mpdf\Mpdf();
$mpdf->WriteHTML("<h1>test</h1>");
$file='abcd.pdf';

$mpdf->OutputHttpDownload($file);

You can use the OutputHttpDownload method passing the name of your file and it will work!

Comments

0

Use this create a temporary directory and then do this

$upload_dir = wp_upload_dir();

$custom_temp_dir = $upload_dir['basedir'] . '/mpdf_temp/';

if (!file_exists($custom_temp_dir)) {
    mkdir($custom_temp_dir, 0755, true);
}
$mpdf = new \Mpdf\Mpdf(['tempDir' => $custom_temp_dir]);
$mpdf->WriteHTML("<h1>test</h1>");
$file='abcd.pdf';
$mpdf->output($file,'F');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.