Sample 38 Protection

00:25:58 Create new PhpWord object
00:25:58 Write to Word2007 format
00:25:58 Write to ODText format
00:25:58 Write to RTF format
00:25:58 Write to HTML format
00:25:58 Write to PDF format
00:25:58 Done writing file(s)
00:25:58 Peak memory usage: 4 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';
}