Skip to content

Converting docx to pdf with phpword #1027

@50l3r

Description

@50l3r

I want to convert a docx file to pdf

I put this line in bootstrap.php

define('PHPWORD_BASE_DIR', realpath(__DIR__));

And my code looks like this:

$FilePath = APPPATH."media/Documentos/Facturas/Factura ".$FacturaId.".docx";
$FilePathPdf = APPPATH."media/Documentos/Facturas/Factura ".$FacturaId.".pdf";

require_once APPPATH.'third_party/phpword/bootstrap.php';

$domPdfPath = realpath(PHPWORD_BASE_DIR . '/../vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererPath($domPdfPath);
\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');

$phpWord = \PhpOffice\PhpWord\IOFactory::load($FilePath);
$pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter( $phpWord, 'PDF' );
$pdfWriter->save($FilePathPdf);

But i got this error:

{"status":false,"error":{"classname":"PhpOffice\\PhpWord\\Exception\\Exception","message":"PDF rendering library or library path has not been defined."}}

I read info about this topic without results: http://stackoverflow.com/questions/25563870/making-dompdf-as-my-pdf-writer-for-phpword


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions