3

私はこれを機能させるために一日中努力してきました。現在、ドキュメントを .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 行目でスローされる

4

3 に答える 3

2

それを知っているので、答えが変わっていると思います:

$includeFile = Settings::getPdfRendererPath() . '/' . $this->includeFile;

$includeFile = Settings::getPdfRendererPath();
于 2015-04-23T21:48:04.597 に答える
0

エラーをログに出力すると、無効な場所から dompdf_config.inc.php を読み込もうとしていることがわかりました。下記参照。

C:\wamp\www\cccake\app\Vendor\dompdf\dompdf.php/dompdf_config.inc.php\n

PHPExcel/PHPWord のクラス ファイルを変更するよりも、ビューの構成を変更する方が賢明です。$rendererLibraryPath で $rendererLibrary を完全に無視すると、問題が解決しました。PHPExcel/PHPExcel は、あなたの場合に dompdf.php ファイル (tcpdf.php) を選択する方法を知っていると思います。以下のコードを試して、うまくいかない場合はお知らせください。

$rendererLibrary = 'tcpdf.php'; $rendererLibraryPath = dirname( FILE ) .'/plugins/tcpdf';

于 2015-06-20T14:17:29.300 に答える