0

I'm a little confused about PHPWord w/ DomPDF. If I generate HTML using Laravel/PHP/Blade, store it in a text file saving it with .html extension, and open it with Word (open Word, select File open, etc), I see the page as I would like to see it in Word.

But if I use PHPWord to write the HTML to a file and then open it as Word2007 for download, PHPWord strips out all the CSS etc. And it looks horrible.

Also while dompdf with the help of PHPWord (again writing the HTML to a file and being read as PDF) the PDF looks much better than the generated Word version but still has no styling.

I have reviewed the samples for each . . . all the articles I can find on here etc. Is there another way to do what I do manually--open the html in Word--for a download with PHP?

I cannot recode the blade template with the PHPWord tagging. But if the Windows laptop Word app can open my HTML and save it as a Word file just fine I would think I could do this relatively easily with PHP programmatically somehow.

STP
  • 51
  • 8
  • You'll need to post some code. Here's some proof that [HTML to DOCX](https://stackoverflow.com/a/62152979/231316) works, and if you read the comments to the question you'll find links for the supported style attributes. – Chris Haas Jun 12 '20 at 20:17
  • Thanks. But I have seen many of those and read the PHPWord and dompdf docs. The problem is still the same (but I cannot find the solution except recoding which is not an option) . . . how can I get a Laravel Blade to process with PHPWord for a docx file creation as well as a dompdf PDF transformation? If I have the complete URL it works great with no error. But I cannot hardcode URLs and change them on all the environments. I have a large dynamic application that I rely on blade templates etc and need to do this programmatically – STP Jun 12 '20 at 21:20
  • actually with nothing left to do I just removed my one at a time. It turns out that our customized bootstrap.css is the problem. . . for dompdf. It causes a unpack(): Type n: not enough input, need 2, have 1 problem. I have no idea where to even start looking inside our css file for that issue and to resolve it. – STP Jun 12 '20 at 21:29
  • When you ask Word to open an HTML document, it launches Word in “HTML editor mode”. Try making the simplest of HTML docs, just a shell plus a strong tag with text, open it in Word, add a new line with italic text and save, and see what HTML Word produces. If it isn’t 100+ lines try again. I say this because Word isn’t HTML. Yes, it know about 90’s tags, but if it isn’t relevant to email (Outlook) it doesn’t support it. – Chris Haas Jun 13 '20 at 02:37

0 Answers0