PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.27k stars 2.7k forks source link

Cannot convert to pdf #1961

Open abunour22 opened 4 years ago

abunour22 commented 4 years ago

Describe the Bug

Invalid characters passed for attempted conversion, these have been ignored

Steps to Reproduce

<?php
              require __DIR__ . '/vendor/autoload.php';

                $template = new\PhpOffice\PhpWord\TemplateProcessor('/doc/profile.docx');
                $template->setValue('q4-no','');
                $template->saveAs('helloWorld2.docx');

                $FilePath = APPPATH."/../helloWorld2.docx";

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

                $wordPdf = \PhpOffice\PhpWord\IOFactory::load($FilePath);
                $pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordPdf , 'PDF');    
                $pdfWriter->save("helloWorld2.pdf", TRUE);

Expected Behavior

Convert Word File to PDF

Current Behavior

A PHP Error was encountered Severity: 8192

Message: Invalid characters passed for attempted conversion, these have been ignored

Filename: Element/Table.php

Line Number: 57

Backtrace:

File: D:\servers\All Projects\Instasmile\server\instasmile 3-7-2019----\application\vendor\phpoffice\phpword\src\PhpWord\Writer\HTML\Element\Table.php Line: 57 Function: hexdec

Context

Please fill in your environment information:

AlbertWesker1988 commented 4 years ago

Describe the Bug

Invalid characters passed for attempted conversion, these have been ignored

Steps to Reproduce

<?php
              require __DIR__ . '/vendor/autoload.php';

                $template = new\PhpOffice\PhpWord\TemplateProcessor('/doc/profile.docx');
                $template->setValue('q4-no','');
                $template->saveAs('helloWorld2.docx');

                $FilePath = APPPATH."/../helloWorld2.docx";

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

                $wordPdf = \PhpOffice\PhpWord\IOFactory::load($FilePath);
                $pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordPdf , 'PDF');    
                $pdfWriter->save("helloWorld2.pdf", TRUE);

Expected Behavior

Convert Word File to PDF

Current Behavior

A PHP Error was encountered Severity: 8192

Message: Invalid characters passed for attempted conversion, these have been ignored

Filename: Element/Table.php

Line Number: 57

Backtrace:

File: D:\servers\All Projects\Instasmile\server\instasmile 3-7-2019----\application\vendor\phpoffice\phpword\src\PhpWord\Writer\HTML\Element\Table.php Line: 57 Function: hexdec

Context

Please fill in your environment information:

  • PHP Version: 7.1
  • PHPWord Version: v0.17.0

If anyone is interested, I can offer a temporary solution. Add to the file vendor/phpoffice/phpword/src/PhpWord/Writer/HTML/Element/Table.php after 55 lines ($cellFgColor = null;) following code: if (strtolower($cellBgColor) === 'auto') { $cellBgColor = null; } I know it's bad practice to edit something in Vendor folder, but before this bug fixing - it can be usefull.

LacourQuentin commented 4 years ago

I know that the following line code help me to escape invalid character for docx document:

Settings::setOutputEscapingEnabled(true);

Maybe it could do the job as well for pdf. Let me know if it works.