Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting docx to pdf with phpword #1027

Closed
50l3r opened this issue Mar 24, 2017 · 6 comments
Closed

Converting docx to pdf with phpword #1027

50l3r opened this issue Mar 24, 2017 · 6 comments

Comments

@50l3r
Copy link

50l3r commented Mar 24, 2017

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:https://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.

@wqj97
Copy link

wqj97 commented Apr 14, 2017

I also got the same problem
Do you find how to fix it?

@50l3r
Copy link
Author

50l3r commented Apr 14, 2017

Try modify this line:

\PhpOffice\PhpWord\Settings::setPdfRendererName('DOMPDF'); //Try uppercase

I solved it but dompdf create a blank file: #1030

Try with libreoffice cli: https://stackoverflow.com/questions/43008759/converting-docx-to-pdf-with-phpword

@kaystrobach
Copy link

@50l3r problem solved? please close issue

@50l3r 50l3r closed this as completed Feb 21, 2019
@SkubaBogdan
Copy link

In my case this error was because of not right path to library.

@JoorgeFerrari
Copy link

I still get a blank file, any solutions of hints by now?

@akashict
Copy link

Still having the same issue, any solutions please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants