Forum


Replies: 4   Views: 497
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 admin  · 02-02-2024 - 06:47

Hello,

To generate a DOCX as a stream you need to enable the streamMode option (https://www.phpdocx.com/api-documentation/performance/zip-stream-docx-with-PHP). For example:

$docx = new CreateDocx();

CreateDocx::$streamMode = true;

$docx->addText($'Text mode.');

$docx->createDocx('output');

In this streamMode, when you call createDocx, the DOCX is generated as a stream, so after calling this method (createDocx) you can do anything you need with this stream.

If you enable $returnDocxStructure you are working with in-memory DOCX documents, not streams. An in-memory DOCX document is not a stream but an object that you can serialize or reuse instead of generating the file. On https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents you can read more information about working with in-memory DOCX documents

About using generateDOCXStructure, this method generates a DOCXStructure (this is an in-memory DOCX document) from a DOCX stream. This DOCXStructure is an in-memory DOCX document that can be used as template with CreateDocxFromTemplate and with other phpdocx methods.
Using phpdocx you can work with DOCX documents from the filesystem, as in-memory DOCX documents (https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents) or as streams (https://www.phpdocx.com/api-documentation/performance/zip-stream-docx-with-PHP).

We recommend you check the examples/Performance folder included in the Premium package that illustrate using generateDOCXStructure, parseDocx, returnDocxStructure and zipStream.

On https://www.phpdocx.com/en/forum/default/topic/2091 you can read a topic with the same stream question and how the user implemented it.

Regards.