Trying this to load a .docx file for eventual conversion to pdf,
and PhpWord can't seem to find the loadFile
function.
use PhpOffice\PhpWord\PhpWord;
...
$phpWord = new PhpWord();
$document = $phpWord->loadFile($filePath);
Tried reinstalling PhpWord with composer & using Settings:: methods from PhpWord.
The __call function in PhpWord.php which is throwing the error:
public function __call($function, $args)
{
$function = strtolower($function);
$getCollection = [];
$addCollection = [];
$addStyle = [];
$collections = ['Bookmark', 'Title', 'Footnote', 'Endnote', 'Chart', 'Comment'];
foreach ($collections as $collection) {
$getCollection[] = strtolower("get{$collection}s");
$addCollection[] = strtolower("add{$collection}");
}
$styles = ['Paragraph', 'Font', 'Table', 'Numbering', 'Link', 'Title'];
foreach ($styles as $style) {
$addStyle[] = strtolower("add{$style}Style");
}
// Run get collection method
if (in_array($function, $getCollection)) {
$key = ucfirst(str_replace('get', '', $function));
return $this->collections[$key];
}
// Run add collection item method
if (in_array($function, $addCollection)) {
$key = ucfirst(str_replace('add', '', $function) . 's');
/** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */
$collectionObject = $this->collections[$key];
return $collectionObject->addItem($args[0] ?? null);
}
// Run add style method
if (in_array($function, $addStyle)) {
return forward_static_call_array(['PhpOffice\\PhpWord\\Style', $function], $args);
}
// Exception
throw new BadMethodCallException("Method $function is not defined.");
}