Forum


Replies: 2   Views: 327
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 crewscontrol  · 20-12-2023 - 22:33

My templates are stored on AWS S3 with private visibility.  I can copy the file over to a local directory and provide CreateDocxFromTemplate with the local path but I'm trying to avoid copying the file to a local directory.

Is there any way to instantiate the class using the raw contents or from a URL?

Thanks.

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.

Posted by crewscontrol  · 21-12-2023 - 13:12

Thank you.  I overlooked this section when searching the documentation.