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

??? symbols after convert docx to pdf file #1296

Open
shevardena opened this issue Feb 24, 2018 · 14 comments
Open

??? symbols after convert docx to pdf file #1296

shevardena opened this issue Feb 24, 2018 · 14 comments

Comments

@shevardena
Copy link

hello, im getting ??? symbols after convert docx to pdf file any ideas how to fix it?

@troosan
Copy link
Contributor

troosan commented Feb 26, 2018

any specifics? Can you post a code sample?

@shevardena
Copy link
Author

see screnshots image
image

actualy word file contains georgian alphabets and only that alphabets converted to ??? in pdf file, see word file screenshot
image

and finaly this is pdf file
image

@troosan
Copy link
Contributor

troosan commented Mar 2, 2018

OK, but that's probably because the font you are using in the PDF does not support UTF-8.

@shevardena
Copy link
Author

Understand. How can i use another font before convert to pdf?

@troosan
Copy link
Contributor

troosan commented Mar 4, 2018

I'm not to familiar with the PDF libraries, but you can set the font on $xmlWriter->setFont('arial');
Also, did you try with other PDF libraries (mpdf or dompdf)?

@autaut03
Copy link

autaut03 commented Mar 6, 2018

@moxetiale I'm very sory for the offtop, but what is your Atom color scheme called?

@shevardena
Copy link
Author

@troosan no i did not try other libraries, i will try setFont thanks
@autaut03 One dark

@jkurowski
Copy link

I have same problem. My .docx file:

Witam,
na imię mam ${variableName} i jestem z Białogardu.

.pdf file:

Witam,
na imi? mam Jacek i jestem z Bia?ogardu.

And my php code:

			require_once LIBRARY_PATH.'/bootstrap.php';
			$phpWord = new \PhpOffice\PhpWord\PhpWord();

			$domPdfPath = realpath(VENDOR_PATH.'/dompdf/dompdf');
			\PhpOffice\PhpWord\Settings::setPdfRendererPath($domPdfPath);
			\PhpOffice\PhpWord\Settings::setPdfRendererName('DomPDF');
			
			$template = new \PhpOffice\PhpWord\TemplateProcessor(FILES_PATH.'/imie.docx');
			$template->setValue('variableName', 'Jacek');
			$template->saveAs(FILES_PATH.'/result.docx');
			
			//Load temp file
			$phpWord = \PhpOffice\PhpWord\IOFactory::load(FILES_PATH.'/result.docx');

			//Save it
			$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
			$xmlWriter->save(FILES_PATH.'/result.pdf'); 

Any suggestions?

@jacklove2run
Copy link

@troosan I have tried the dompdf, the same reasult. I will try $xmlWriter->setFont('arial') later.

@jkurowski
Copy link

jkurowski commented Mar 29, 2018

$xmlWriter->setFont('arial') - dont work

This is working:

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

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

$template = new \PhpOffice\PhpWord\TemplateProcessor(FILES_PATH.'/imie.docx');
$template->setValue('variableName', 'Jacek');
$template->saveAs(FILES_PATH.'/result.docx');

//Load temp file
$phpWord = \PhpOffice\PhpWord\IOFactory::load(FILES_PATH.'/result.docx');

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save(FILES_PATH.'/hello.html');
chmod(FILES_PATH.'/hello.html', 0777);

$dompdf = new \Dompdf\Dompdf();
$dompdf->load_html(file_get_contents(FILES_PATH.'/hello.html'));

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();
$pdf_string = $dompdf->output();
file_put_contents(FILES_PATH.'/result2.pdf', $pdf_string);

And in file: phpword\src\PhpWord\Writer\HTML\Part\Head.php

        $content .= '<head>' . PHP_EOL;
        $content .= '<meta charset="UTF-8" />' . PHP_EOL;
        $content .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . PHP_EOL;
        $content .= '<title>' . $title . '</title>' . PHP_EOL;
        // foreach ($propertiesMapping as $key => $value) {
            // $value = ($value == '') ? $key : $value;
            // $method = 'get' . $key;
            // if ($docProps->$method() != '') {
                // $content .= '<meta name="' . $value . '"'
                          // . ' content="' . (Settings::isOutputEscapingEnabled() ? $this->escaper->escapeHtmlAttr($docProps->$method()) : $docProps->$method()) . '"'
                          // . ' />' . PHP_EOL;
            // }
        // }
        //$content .= $this->writeStyles();
		$content .= '<style>body {font-family: DejaVu Sans, sans-serif}</style>' . PHP_EOL;
        $content .= '</head>' . PHP_EOL;

@neverovski
Copy link

neverovski commented Apr 2, 2018

@jkurowski When composer update or composer install, phpword\src\PhpWord\Writer\HTML\Part\Head.php - will change.

Better:
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setName('DejaVu Sans, sans-serif');

@davisphper
Copy link

Do you have a solution for the same problem?

@ideamk
Copy link

ideamk commented Jul 14, 2021

$fontStyleName = 'oneUserDefinedStyle';
$phpWord->addFontStyle(
    $fontStyleName,
    array('name' => 'DejaVu Sans', 'size' => 10)
);

Works for me. Fonts location in /vendor/dompdf/dompdf/lib/fonts, by default install from composer.

@SarahTrees
Copy link
Contributor

Support question successfully answered.
Sample code works.
Issue can be marked as closed.

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

9 participants