Forum


Replies: 1   Views: 79
Change filename of streamed pdf or get in memory pdf from transform

Posted by admin  · 11-10-2024 - 11:23

Hello,

There's no option in the current stable release of phpdocx to customize the Content-Disposition value when streaming a PDF using TransformDocAdvPDF.

We have added support in the testing branch. Please edit TransformDocAdvPDF.php and replace the following line:

$this->pdf->stream();

with:

$this->pdf->stream($target);

After this change, the target value will be used in Content-Disposition. This same change will be included in the next stable release of phpdocx.

Alternatively, you could use ob_ PHP methods (https://www.php.net/manual/en/ref.outcontrol.php) to get the PDF content and return it as needed:

$docx = new CreateDocx();
CreateDocx::$streamMode = true;
ob_start();
$docx->transformDocument('document.docx', 'document.pdf', 'native', array('dompdf' => $dompdf));
$pdfContent = ob_get_clean();
ob_end_clean();
// custom headers...
echo $pdfContent;
ob_end_flush();

Regards.