我用laravel我的應用程序和DOMPDF中發現:製作DOMPDF爲我的PDF作家phpWord
../vendor/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}}
我怎麼會讓DOMPDF爲我的PDF作家PHPWord?我無法找到任何其他選項,所以我在這裏問。我希望你能幫助我。謝謝!
你試過dompdf庫的絕對路徑嗎? – BrianS 2014-09-12 03:04:24