私はこれを機能させるために一日中努力してきました。現在、ドキュメントを .docx ファイルとして保存できますが、ドキュメントを PDF として保存できるようにしたいと考えていました。 . 何か不足していますか?ご協力ありがとうございました
$rendererName = \PhpOffice\PhpWord\Settings::PDF_RENDERER_TCPDF;
$rendererLibrary = 'tcpdf.php';
$rendererLibraryPath = dirname(__FILE__) .'/plugins/tcpdf/' . $rendererLibrary;
\PhpOffice\PhpWord\Settings::setPdfRenderer($rendererName,$rendererLibraryPath);
$document->saveAs('temp.docx'); // Save to temp file
$test = \PhpOffice\PhpWord\IOFactory::load('temp.docx'); // Read the temp file
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($test, 'PDF');
$xmlWriter->save('result.pdf'); // Save to PDF
unlink('temp.docx'); // Delete the temp file
エラーをスローしているコードは次のとおりです
public function __construct(PhpWord $phpWord)
{
parent::__construct($phpWord);
$includeFile = Settings::getPdfRendererPath() . '/' . $this->includeFile;
if (file_exists($includeFile)) {
/** @noinspection PhpIncludeInspection Dynamic includes */
require_once $includeFile;
} else {
// @codeCoverageIgnoreStart
// Can't find any test case. Uncomment when found.
throw new Exception('Unable to load PDF Rendering library');
// @codeCoverageIgnoreEnd
}
}
ここに完全なエラーがあります
致命的なエラー: .../PHPWord/Writer/PDF/AbstractRenderer.php:92 で「PDF レンダリング ライブラリを読み込めません」というメッセージを含むキャッチされない例外「PhpOffice\PhpWord\Exception\Exception」が発生しました: スタック トレース: #0 .../PHPWord /Writer/PDF.php(61): PhpOffice\PhpWord\Writer\PDF\AbstractRenderer->__construct(Object(PhpOffice\PhpWord\PhpWord)) #1 .../PHPWord/IOFactory.php(34): PhpOffice\PhpWord \Writer\PDF->__construct(Object(PhpOffice\PhpWord\PhpWord)) #2 .../download_report.php(578): PhpOffice\PhpWord\IOFactory::createWriter(Object(PhpOffice\PhpWord\PhpWord), 'PDF ') #3 {main} が .../PHPWord/Writer/PDF/AbstractRenderer.php の 92 行目でスローされる