アプリに laravel を使用しましたが、dompdf は次の場所にあります。
../ベンダー/dompdf/dompdf
私が達成したかったのは、.docx ファイル (Microsoft Word) を .pdf ファイルに変換することです。docx ファイルは、テンプレート ファイルを読み込んで値を置き換えることにより、phpWord によって生成されました。
スニペットは次のとおりです。
// Get the absolute path of the template file
$wordTemplatePath = $this->getDocumentTemplatePath('resignation.docx');
// Load the template file
$document = $this->phpWord->loadTemplate($wordTemplatePath);
// This will be filled with data
$wordData = []
.... Process to fill the data .....
// Replace value to actual word document
$this->setTemplateValues($wordData, $document);
// Generate its filename
$file = $this->generateFileName('Retirement-Certificate.docx', $id);
// Fetch the absolute path to save the document
$filepath = $this->getSavePath($file);
// Save the word document
$document->saveAs( $filepath );
その後、.docx ファイルが生成されます。それのPDF版も作りたかった。そこで、このコード スニペットを検索して見つけ、コードに追加しました。
\PhpOffice\PhpWord\Settings::setPdfRendererPath('../vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DOMPDF');
//Load temp file
$phpWord = \PhpOffice\PhpWord\IOFactory::load($filepath);
//Save it
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('result.pdf');
しかし、私はこのエラーが発生しました:
{"error":
{"type":"PhpOffice\\PhpWord\\Exception\\Exception","message":"PDF rendering library or library path has not been defined.",
"file":"C:\\xampp\\htdocs\\vagrant\\vendor\\phpoffice\\phpword\\src\\PhpWord\\Writer\\PDF.php",
"line":49}}
PHPWord の PDF ライターとして DomPDF を作成するにはどうすればよいですか? 他に選択肢がないのでこちらで質問させていただきます。あなたが私を助けてくれることを願っています。ありがとう!