Forum


Replies: 2   Views: 331
Other means to instantiate a template other than from a path
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  · 21-12-2023 - 06:07

Hello,

With a Premium license you can use in-memory DOCX documents:

// this object can be serialized (in memory, database, file system...) to be reused later
$docxStructure = new DOCXStructure();
$docxStructure->parseDocx('document.docx');

$docx = new CreateDocxFromTemplate($docxStructure);

or generate a DOCXStructure object (this approach uses stream_get_contents to get a stream but it also generates a local temp file with the DOCX, needed by ZipArchive):

$docxStructureStream = new DOCXStructureFromStream();
$docxStructure = $docxStructureStream->generateDOCXStructure('http://www.phpdocx.com/files/samples/TemplateSimpleText.docx');

$docx = new CreateDocxFromTemplate($docxStructure);

On https://www.phpdocx.com/documentation/cookbook/in-memory-docx-documents you can read more information about these methods.

Regards.