Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Nublust's avatar

Converting .docx to PDF

I'm currently using PHPWord (https://github.com/PHPOffice/PHPWord) to process a template and create .docx files in a project. Now I need to convert them to PDF files. The PHPWord converter is not working ( https://github.com/PHPOffice/PHPWord/issues/472 ) so I cannot use that. Can anyone recommend something to achieve this?

0 likes
7 replies
EliasSoares's avatar

Unfortunatelly PHPWord is abandoned. No more commits, no more merged pull requests, last version was at Agoust with slight differences.

I use it, but it's terrible buggy. Some bugs, you will need to fix yourself.

Good luck!

jlrdw's avatar

Word 2007 and up has it build in.

1 like
andreasb's avatar

Hi guys

I wanted to bring this up because I have exactly the same issue as the topic starter, @nublust .

Now just to correct this @eliassoares , PHPWord does not seem to be abandoned. There were several releases in the past months and it is still maintained and bugfixing is going on.

Now as of today:

  • TCPDF: The current version is end of life and not supported anymore, but there is a new one being developed at https://github.com/tecnickcom/tc-lib-pdf which however is not yet finished so it is not a good idea to use TCPDF as we speak (I tried to use the "old" version and the PDF came out missing 90% of the very simpel word document).
  • phpgearbox/pdf is also abandoned. The author recommends athenapdf, but athenapdf is based on docker so lots of work to setup and maintain. IIRC it also used wkhtmltopdf which is CLI based and I don't like that.
  • Which leaves DomPDF. The current version seems to be incompatible with PHPWord out of the box, but with a bit of tweaking it is "working" - see https://github.com/PHPOffice/PHPWord/issues/995 for reference. "Working" because similarly with TCPDF, my simple word file looks completely destroyed also with DomPDF, most probably because I am converting .docx to .pdf and not .html to .pdf because I am using a word-file based template.

So long story short: has oneone found a good/stable solution for this yet? @nublust , what did you end up working with?

Thanks Andreas

kurucu's avatar

For anyone stumbling here. I haven't got things to convert to PDF yet, but that's not far away. As PHPWord is still moving pretty slowly, I took an alternative approach, which I got working in an afternoon as is now a backbone to my project.

I have a simple Express app which accepts a single POST endpoint with the body being a json representation of my document. Laravel passes my document to the Express app, and in return, Express sends a Word document as an attachment using docx.js.org to turn my json into the Word document. It sounds convoluted, but really it's a single endpoint, with a few loops (document>sections>paragraphs) and some if statements to convert headings, paragraphs, list items etc.

It's definitely been the most powerful way to do this, as the docx js library is very good. Then back to Laravel to the rest.

1 like

Please or to participate in this conversation.