2017-03-24 3 views
0

Ich mag eine docx-Datei in PDF konvertieren mit phpwordKonvertieren docx zu pdf mit phpword

mein Code wie folgt aussieht:

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

//DOCX TO PDF 
require_once APPPATH.'third_party/phpword/bootstrap.php'; 

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

$phpWord = new \PhpOffice\PhpWord\PhpWord(); 

//Load temp file 
$phpWord = \PhpOffice\PhpWord\IOFactory::load($FilePath); 

//Save it 
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF'); 
$xmlWriter->save($FilePathPdf, true); 

Aber ich erzeugen eine leere PDF-Datei: LINK TO FILE

Pfade sind korrekt und .docx haben Inhalt

Ich versuche mit tcpdf render:

$rendererLibraryPath = PHPWORD_BASE_DIR . '/vendor/tecnickcom/tcpdf'; 
\PhpOffice\PhpWord\Settings::setPdfRendererPath($rendererLibraryPath); 
\PhpOffice\PhpWord\Settings::setPdfRendererName('TCPDF'); 

und meine pdf-Datei 2 Seiten ohne Inhalt: LINK TO 2ND FILE

Antwort

1

Schließlich fand ich eine kostenlose Alternative Lösung Installation von Libreoffice:

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

require_once APPPATH.'third_party/phpword/bootstrap.php'; 
$template = new \PhpOffice\PhpWord\TemplateProcessor(APPPATH.'media/Plantillas/Factura/Factura.docx'); 

foreach($data as $key => $value){ 
    $template->setValue($key, $value); 
} 

$template->saveAs($FilePath); 

shell_exec($this->CI->config->item('libreoffice_exec')." --headless --convert-to pdf --outdir \"".$Path."\" \"$FilePath\""); 

Aufruf soffice.exe CLI mit diesem Parameter:

soffice.exe --headless --convert-to pdf --outdir "C:/media/Documentos/Facturas/pdf" "C:/media/Documentos/Facturas/Factura1.docx"; 
Verwandte Themen