Forum


Replies: 1   Views: 443
How to compress pdfs and reduce file size ?
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 23-05-2024 - 07:54

Hello,

Unfortunately, MS Word doesn't include options to reduce or optimize the PDF output size. In this case, the best approach would be using an external tool installed on the server, such as GhostsScript:

https://www.digitalocean.com/community/tutorials/reduce-pdf-file-size-in-linux

https://gist.github.com/ahmed-musallam/27de7d7c5ac68ecbd1ed65b6b48416f9

GhostScript is available for Windows, Linux and macOS and you can run it from PHP using shell_exec.

Please note that in most cases, a large PDF file size is due to the images. As alternative approach to using GhostScript, you could try to optimize the DOCX file with optimizeDocx (using imageFiles and imageFilesToJpegLevel options to optimize the images) before being transformed to PDF.

Regards.