2017-03-24 1 views
0

Je veux convertir un fichier docx en pdf en utilisant phpwordConversion docx en pdf avec phpword

mon code ressemble à ceci:

$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); 

Mais je générer un fichier vide pdf: LINK TO FILE

Les chemins sont corrects et .docx ont le contenu

J'essaie avec le rendu tcpdf:

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

et mon fichier pdf ont 2 pages sans contenu: LINK TO 2ND FILE

Répondre

1

Enfin j'ai trouvé une LibreOffice installation de solution alternative gratuite:

$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\""); 

appel CLI soffice.exe avec ces paramètres:

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