Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsequent calls to Output() of pdf with images are missing images in 2++ data #2026

Closed
1 task done
manitu-opensource opened this issue Jun 14, 2024 · 1 comment
Closed
1 task done

Comments

@manitu-opensource
Copy link

manitu-opensource commented Jun 14, 2024

Guidelines

Description of the bug

When calling Output() on a mpdf which has images for 2 or more times the subsequent calls to Output() are missing the images.

Background: Maybe you want to show a Mpdf in browser and save it in filesystem, so one would call $mpdf->Output() and $mpdf->Output('some_filename', 'F');

The second, third, ... calls to Output() are generating pdf data / files which have images missing.

The reason is in mpdf/mpdf/src/Writer/ImageWriter.php line 96:

unset($this->mpdf->images[$file]['data']);

The image file data are cleaned after the first Output()call.

Even clone of the $mpdf object will not help since the ImageWriter class has its own reference to the original mpdf object.

mPDF version

8.2.3 / current

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

PHP 8.1 / 8.2 / 8.3

Reproducible PHP+CSS+HTML snippet suffering by the error

  1. Generate new mpdf
  2. Add images
  3. Call $mpdf->Output() for the first time
  4. Call $mpdf->Output() for the second time

The problem is also seen in php error / warning log
strlen(): Passing null to parameter #1 ($string) of type string is deprecated

which occurs in the second call.

@finwe
Copy link
Member

finwe commented Jun 14, 2024

mPDF does not work well with consecutive Output calls. Create a separate instance for each desired Output.

The second Output call could throw an Exception, maybe in future versions.

@finwe finwe closed this as completed Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants