Forum


Replies: 4   Views: 450
Return a docx as a stream
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by khalid-s  · 01-02-2024 - 22:29

Hi, I am currently struggling with returning a docx as a stream in a symfony app.

Here is what i got 

 

#[Route('/', name: 'app_app')]
public function index(): StreamedResponse
{
    $doc = new CreateDocx();
    CreateDocx::$streamMode = true;
    CreateDocx::$returnDocxStructure = true;

    $doc->addText('This is a test');
    $doc->embedHTML('<p style="font-size: 30px;">New paragraph</p>');

    return new StreamedResponse(function () use ($doc) {
        $stream = fopen('php://output', 'wb');
        stream_copy_to_stream($doc, $stream);
    });
}

 

Of course this cannot work since the $doc in my stream_copy_to_stream is not a resource. How can i transform it as a resource.