When generating a file from a word template, is it possible to delete personal data left in the template? For example, the author's name.
I checked if the author's name is left in the template, in the new files received based on this template, this author's name is copied, which is not correct, because is personal data.
I have a lot of templates and it’s problematic to manually delete personal data from them; they are also often edited and sometimes you forget to delete this data from them.
When generating a file from a word template, is it possible to delete personal data left in the template? For example, the author's name.
I checked if the author's name is left in the template, in the new files received based on this template, this author's name is copied, which is not correct, because is personal data.
I have a lot of templates and it’s problematic to manually delete personal data from them; they are also often edited and sometimes you forget to delete this data from them.
Share Improve this question edited Feb 6 at 10:59 Dmitriy asked Feb 5 at 11:33 DmitriyDmitriy 95 bronze badges 5 |1 Answer
Reset to default 0I found answer based on comment from @C3roe:
$templateProcessor = new TemplateProcessor($templateFileLink);
$templateProcessor->saveAs($resultFileLink);
$objReader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
/** @var PhpWord $phpWord */
$phpWord = $objReader->load($resultFileLink); // instance of \PhpOffice\PhpWord\PhpWord
/** @var DocInfo $properties */
$properties = $phpWord->getDocInfo();
$properties->setCreator('');
$properties->setModified(false);
$properties->setLastModifiedBy('');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($resultFileLink);
setCreator
method is for? phpoffice.github.io/PHPWord/docs/classes/… – C3roe Commented Feb 5 at 11:42$templateProcessor = new TemplateProcessor($templateFileLink); $templateProcessor->saveAs($resultFileLink);
That all of code. – Dmitriy Commented Feb 6 at 10:14