mercredi 5 décembre 2018

Error converting .docx file (with .emf image background) to PDF

A Laravel-based application is converting documents (.doc, .docx, .pdf, .png, .otd, html, etc) to PDF so that they can all be merged together into a master PDF document. It is using a combination of plugins like PHPWord and DOMPDF Wrapper to do the file loading and creation. Every once and awhile, the process encounters an error due to a Word file.

ERROR: PhpOffice\PhpWord\Exception\InvalidImageException: Invalid image: zip:// ... #word/media/image2.emf

The error is caused by an image background within the document that acts like a watermark. The PHPWord part that errors out is the PhpOffice\PhpWord\Element\Image->checkImage() method, but happens when the file is trying to be loaded.

Settings::setPdfRendererName(Settings::PDF_RENDERER_DOMPDF);
$pdfWord = IOFactory::load(storage_path() . '/app/uploads/randomfile.docx', 'Word2007');

How can the application convert a Word document, with an EMF image embedded, to a PDF?

For more code/info on how to recreate the error, a few issues exist in the Github PHPWord library.

  1. Support EMF image #1480
  2. Read docx error when contains image from remote url #1173

The environment-related information:

  • Server: Windows / IIS
  • PHP: 7.2.11
  • Laravel: 5.7.15
  • PHPWord: 0.15.0


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2rv2smx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire