Forum


Replies: 10   Views: 171
Using dompdf with the native conversion plugin

Posted by Damian Rousseau  · 28-10-2024 - 10:38

Hello.

I meet a problem with Dompdf when i try to transform docx to pdf.

First i create docx form template, then i replace variable by word fragment and text, save it to .docx.

Than i wanted to transform it to pdf before download it by the users :

// Here PDF => Barryvdh\DomPDF\Facade::class

$dompdf = new PDF();
$transform = new \Phpdocx\Transform\TransformDocAdvNative();
$transform->transformDocument(public_path('contrats').'/contrat_formate.docx', public_path('contrats').'/contrat_formate_pdf.pdf', array('dompdf' => $dompdf));

But i meet this error :

Undefined property: Barryvdh\DomPDF\Facade\Pdf::$version

Thanks for the help !

Posted by admin  · 28-10-2024 - 11:00

Hello,

Please note that https://github.com/barryvdh/laravel-dompdf is a wrapper for calling some DOMPDF methods. phpdocx requires using DOMPDF directly, so we recommend you use https://github.com/dompdf/dompdf.

To use a wrapper such as https://github.com/barryvdh/laravel-dompdf, you'd need to get the Dompdf instance. For example, using the getDomPDF method from this library, and then pass it to the phpdocx method. We recommend you use https://github.com/dompdf/dompdf.

Regards.

Posted by Damian Rousseau  · 28-10-2024 - 11:16

Many thanks for your reply.

It work with the first page of my file, but i've a 500 server error when i try to convert all the file. Is my file to big ?

Posted by admin  · 28-10-2024 - 11:36

Hello,

We recommend you check the server logs. Maybe you need to increase the available memory for PHP or the maximum time a PHP script can run. The server logs must contain the exact PHP error and the needed changes in the PHP ini file to solve it.

Regards.

Posted by Damian Rousseau  · 28-10-2024 - 12:33

Okay after see the logs, i think the problem come from the typo i use in my .docx file :

[28-Oct-2024 12:04:05 Europe/Paris] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /Applications/MAMP/htdocs/pfd_project/vendor/dompdf/dompdf/src/Css/Stylesheet.php on line 1040

 

Posted by admin  · 28-10-2024 - 13:28

Hello,

The following error:

PHP Fatal error: Maximum execution time of 30 seconds exceeded

is a PHP error that appears when a script exceeds the maximum time allowed in PHP.
On the following pages, you can read more information about this PHP question:

https://www.php.net/manual/en/function.set-time-limit.php

https://stackoverflow.com/questions/5164930/fatal-error-maximum-execution-time-of-30-seconds-exceeded

As explained in our previous reply, you may need to increase the available memory for PHP or the maximum time a PHP script can run on the PHP settings of the server you are using.

Please note that Dompdf requires significant memory and time to generate a big PDF. Other conversion plugins such as the one based on LibreOffice are faster. On https://www.phpdocx.com/documentation/conversion-plugin are detailed the available conversion plugins and how to configure and use them.

Regards.

Posted by Damian Rousseau  · 28-10-2024 - 15:18

I don't think it'll correct the problem, i've the same error even if only one page and Arial typo.

Posted by admin  · 28-10-2024 - 15:44

Hello,

Please note that as explained in our previous reply, the following error:

PHP Fatal error: Maximum execution time of 30 seconds exceeded

is a PHP error that appears when a script exceeds the maximum time allowed in PHP.

It's not directly related to phpdocx but to the PHP settings you are using and the time taken by the script to finish. This error is not from the font used in the DOCX (although adding new fonts to DOMPDF may increase the time taken to run a script). Logically, if the document is larger, it will take longer to convert.
This same error will appear when running any PHP script that exceeds the maximum execution time of the PHP settings of the server you are using. You need to adjust the PHP settings on your server.

Regards.

Posted by Damian Rousseau  · 29-10-2024 - 09:28

I've find the problem, i come from my image (to big, it created infinit loop).

But now i'm facing another little issue : the style of my .docx isn't apply when it transform into .pdf

Is there something i'm doing wrong ?

$dompdf = new \Dompdf\Dompdf();
$transform = new \Phpdocx\Transform\TransformDocAdvNative();
$transform->transformDocument(public_path('contrats').'/contrat_formate.docx', public_path('contrats').'/contrat_formate_pdf.pdf', array('dompdf' => $dompdf));

 

Posted by admin  · 29-10-2024 - 10:06

Hello,

Please note that the native conversion plugin supports a set of contents and styles detailed at https://www.phpdocx.com/documentation/conversion-plugin/preparing-the-templates-for-its-conversion (Supported OOXML tags and attributes when using the native method section).

If the DOCX to be transformed uses contents and styles not supported by the native conversion plugin, it's recommended/required to use the conversion plugin based on LibreOffice to get a proper output, as advised on the documentation pages (https://www.phpdocx.com/documentation/conversion-plugin/information  Which method to use for the conversion? section). The conversion plugin based on MS Word can also be used.

Regards.

Posted by Damian Rousseau  · 29-10-2024 - 13:39

Many thanks, i found all what i need on the GIthub of DOMpdf (like all the Font it accept, etc ...)

Best regards.