{"record":{"id":"2828bfc10db2ab5e","repo":"PHPOffice/PHPWord","slug":"name-is-not-a-valid-writer","errorCode":null,"errorMessage":"\"{$name}\" is not a valid writer.","messagePattern":"\"(.+?)\" is not a valid writer\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/PhpWord/IOFactory.php","lineNumber":40,"sourceCode":"use PhpOffice\\PhpWord\\Element\\TextRun;\nuse PhpOffice\\PhpWord\\Exception\\Exception;\nuse PhpOffice\\PhpWord\\Reader\\ReaderInterface;\nuse PhpOffice\\PhpWord\\Writer\\WriterInterface;\nuse ReflectionClass;\n\nabstract class IOFactory\n{\n    /**\n     * Create new writer.\n     *\n     * @param string $name\n     *\n     * @return WriterInterface\n     */\n    public static function createWriter(PhpWord $phpWord, $name = 'Word2007')\n    {\n        if ($name !== 'WriterInterface' && !in_array($name, ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPub3'], true)) {\n            throw new Exception(\"\\\"{$name}\\\" is not a valid writer.\");\n        }\n\n        $fqName = \"PhpOffice\\\\PhpWord\\\\Writer\\\\{$name}\";\n\n        return new $fqName($phpWord);\n    }\n\n    /**\n     * Create new reader.\n     *\n     * @param string $name\n     *\n     * @return ReaderInterface\n     */\n    public static function createReader($name = 'Word2007')\n    {\n        return self::createObject('Reader', $name);\n    }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/IOFactory.php#L22-L58","documentation":"IOFactory::createWriter() only allows the writer names 'ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPub3' (plus the internal 'WriterInterface' marker). Any other $name throws a PhpWord Exception before attempting to instantiate PhpOffice\\PhpWord\\Writer\\{$name}. 'PDF' resolves to the PDF writer wrapper, which itself requires an underlying PDF library.","triggerScenarios":"IOFactory::createWriter($phpWord, 'DOCX'), createWriter($phpWord, 'word2007') (case-sensitive), or passing a writer class FQCN instead of the short name.","commonSituations":"Case mismatches ('Word2007' vs 'word2007'), using format extensions as names ('docx'), expecting 'PDF' to work without a configured PDF renderer (DomPDF/TCPDF), or older/newer PhpWord versions with a different writer list.","solutions":["Use one of the exact names: 'Word2007' (for .docx), 'ODText', 'RTF', 'HTML', 'PDF', 'EPub3'.","Mind case sensitivity — 'word2007' is rejected; use 'Word2007'.","Omit the $name argument to default to 'Word2007'.","If using 'PDF', install/configure a supported PDF library (e.g. dompdf/tcpdf) or write Word2007 and convert externally."],"exampleFix":"// before\n$writer = IOFactory::createWriter($phpWord, 'DOCX');\n// after\n$writer = IOFactory::createWriter($phpWord, 'Word2007');","handlingStrategy":"validation","validationCode":"$writers = ['ODText', 'RTF', 'Word2007', 'HTML', 'PDF', 'EPub3'];\nif (!in_array($name, $writers, true)) { $name = 'Word2007'; }","typeGuard":"function isValidWriterName(string $name): bool { return in_array($name, ['ODText','RTF','Word2007','HTML','PDF','EPub3'], true); }","tryCatchPattern":"try { $writer = IOFactory::createWriter($phpWord, $name); } catch (\\PhpOffice\\PhpWord\\Exception\\Exception $e) { $writer = IOFactory::createWriter($phpWord, 'Word2007'); }","preventionTips":["Use exact case-sensitive writer names ('Word2007', not 'docx')","Default to Word2007 when unsure","Install a PDF renderer (dompdf/tcpdf) if using the 'PDF' writer"],"tags":["phpword","writer","invalid-argument","iofactory"],"backgroundTag":"invalid-enum-value","analyzedSha":"aef95c04151b5633cc505f672ddd6a71da900ee1","analyzedAt":"2026-09-14T10:53:58.933Z","contentChangedAt":"2026-09-14T10:53:58.933Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}