25 lines
905 B
PHP
25 lines
905 B
PHP
<?php
|
|
// Init
|
|
error_reporting(\E_ALL);
|
|
define('EOL', (\PHP_SAPI == 'cli') ? \PHP_EOL : '<br />');
|
|
require_once '../src/PhpWord.php';
|
|
|
|
// Read contents
|
|
$name = basename(__FILE__, '.php');
|
|
$source = "resources/{$name}.docx";
|
|
echo date('H:i:s'), " Reading contents from `{$source}`", \EOL;
|
|
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
|
|
|
|
// (Re)write contents
|
|
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
|
foreach ($writers as $writer => $extension) {
|
|
echo date('H:i:s'), " Write to {$writer} format", \EOL;
|
|
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
|
|
$xmlWriter->save("{$name}.{$extension}");
|
|
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
|
}
|
|
|
|
// Done
|
|
echo date('H:i:s'), " Done writing file(s)", \EOL;
|
|
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", \EOL;
|