Forum


Replies: 9   Views: 1820
How to use the streammode?
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 pwctechnicalsecurity  · 02-04-2021 - 16:22

Hi,

Thanks for the suggestion; I think I can manage myself, if only the online documentation would be more specific (or available in the first place). I think the community would greatly benefit from a simple working example with popular frameworks - especially, considering Laravel is using Symfony (Symfony\Component\HttpFoundation\StreamedResponse) and more and more frameworks are using Symfony components. Providing a public accessible Symfony example would probably address a lot of situations already.

Let me phrase it differently (as probably already 90% of the code is probably there already):

\Phpdocx\Create\CreateDocx::$returnDocxStructure = true;
$queue = array();
$docx = new \Phpdocx\Create\CreateDocxFromTemplate('/path_to_.docx');
$queue[] = $docx->createDocx();

$merge = new \Phpdocx\Utilities\MultiMerge();
$result = $merge->mergeDocx($queue[0], array(), 'example.docx', array());

return response()->streamDownload(function () use ($result) {

    echo $result;

}, 'document.docx');

I figure that, having the MultiMerge instance return DocXStructure (instead of having it created on the filesystem when $returnDocxStructure = false) and taking ownership of the streaming mode (as not setting streamMode to true, because that actually intervenes with the regular Controller / Response behavior).

Hence, while the above example is not correct, it should come very close. Let me phrase it like this: what output do I need to have from PhpDocx (DocX, Docx Structure?) in order to stream the result (without touching the filesystem)?