mpdf/psr-http-message-shim
PSR-7 HTTP message shim used by mPDF, providing lightweight interface-compatible request/response/message classes for projects that can’t rely on a full PSR-7 implementation. Helps maintain interoperability with minimal dependencies.
This package provides a lightweight PSR-7/PSR-17 implementation shim for mpdf, bridging PSR HTTP messages and mPDF’s internal stream handling. Start by installing it via Composer:
composer require mpdf/psr-http-message-shim
The most common immediate use case is passing PSR-7 StreamInterface objects (e.g., from uploaded files or Symfony/Guzzle requests) directly to mPDF’s Output() method or constructors that accept streams—avoiding manual fopen()/fread() boilerplate.
StreamFactory (e.g., Nyholm/psr7 or GuzzleHttp\Psr7) and use the shim to convert streams for mPDF:
$stream = $streamFactory->createStreamFromFile('/tmp/report.pdf');
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output($stream, \Mpdf\Output\Destination::STREAM); // Uses shim internally if available
$stream = (newStreamFactory())->createStream();
$mpdf->Output($stream, Destination::STREAM);
$pdfContent = $stream->getContents();
$this->assertStringContainsString('%PDF-1.4', $pdfContent);
StreamFactory in AppServiceProvider and inject it where generating dynamic PDFs (e.g., from queued jobs), using the shim to unify stream sources.composer.json’s require (not just require-dev).Destination::STREAM and Destination::DOWNLOAD. Use Destination::FILE or Destination::STRING for non-stream operations—this package won’t help there.StreamWrapper::createStream() from GuzzleHttp\Psr7 if mocking with non-seekable sources.MpdfPsrStreamTrait for low-level insight if subclassing mPDF or writing a custom output destination.How can I help you explore Laravel packages today?