PHP Classes

Password protect the generated document

Recommend this page to a friend!

      PHP DOCX Template  >  All threads  >  Password protect the generated document  >  (Un) Subscribe thread alerts  
Subject:Password protect the generated document
Summary:Password protect Docx
Messages:1
Author:Sujan
Date:2020-12-20 13:07:18
 

  1. Password protect the generated document   Reply   Report abuse  
Picture of Sujan Sujan - 2020-12-20 13:07:18
Hi,
The package is great and renders everything perfectly.
Maybe this is an additional feature request but I was trying to add password to the generated docx (using this class) by loading it into another package(phpOffice) and then adding a password and then rewriting the original document again. It doesnt work.
// $fileName = "merges/test.docx";
// $phpWord = PhpOffice\PhpWord\IOFactory::load($fileName);
// $documentProtection = $phpWord->getSettings()->getDocumentProtection();
// $documentProtection->setEditing(DocProtect::READ_ONLY);
// $documentProtection->setPassword('myPassword');
// $documentProtection->saveAs("merges/test.docx");

The styling and the variable merge tags are all a mess. Trying to do this for days now.
Maybe this class can have a password protect function for setting password to the generated docx using variables?
Please help.

Thank you,
#