'array' ]; /** * Подстановка значений в DOCX шаблон */ public function generateDocument($data) { $tempDir = storage_path('app/temp/' . uniqid()); mkdir($tempDir, 0755, true); // Копируем исходный шаблон $templatePath = $tempDir . '/template.docx'; copy($this->source_path, $templatePath); $docx = new DocxTemplateProcessor(); // Подставляем значения $changedDocxPath = $docx->processWithPhpWord($templatePath, $data); // Возвращаем путь к сгенерированному файлу return $changedDocxPath; } /** * Конвертация в PDF для предпросмотра */ public function convertToPdf($docxPath) { $pdfPath = str_replace('.docx', '.pdf', $docxPath); // Надо добавить.... $home = config('libreoffice.home'); $user = config('libreoffice.user'); putenv("HOME=$home"); putenv("USER=$user"); $command = "libreoffice --headless --convert-to pdf --outdir " . escapeshellarg(dirname($pdfPath)) . " " . escapeshellarg($docxPath); $result = shell_exec($command . " 2>&1"); if (!file_exists($pdfPath)) { throw new \Exception("PDF conversion failed: " . $result); } return $pdfPath; } }