Sample 38 Protection

04:17:44 Create new PhpWord object
04:17:44 Write to Word2007 format
04:17:44 Write to ODText format
04:17:44 Write to RTF format
04:17:44 Write to HTML format
04:17:44 Write to PDF format
04:17:44 Done writing file(s)
04:17:44 Peak memory usage: 8 MB

 

Results: docx odt rtf html pdf


<?php

use PhpOffice\PhpWord\SimpleType\DocProtect;

include_once 
'Sample_Header.php';

// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();

$documentProtection $phpWord->getSettings()->getDocumentProtection();
$documentProtection->setEditing(DocProtect::READ_ONLY);
$documentProtection->setPassword('myPassword');

$section $phpWord->addSection();
$section->addText('this document is password protected');

// Save file
echo write($phpWordbasename(__FILE__'.php'), $writers);
if (!
CLI) {
    include_once 
'Sample_Footer.php';
}