简体   繁体   中英

Converting PPTX to PDF with PHP

I am developing an API, in PHP, hosted on a linux server, that requires me to make jpeg previews for a .pptx powerpoint presentation.

I first convert the file to pdf and then convert the pdf to jpegs. The second step is easy, with ghostscript, it's the first part that's proving difficult.

  • I have tried using the libreoffice executable, but pptx isn't completely compatible. Certain backgrounds become invisible.

  • I have the same problem with many 3rd party APIs (which I suspect also use libreoffice); the ones that do work, are ridiculously expensive.

  • Installing office on a Linux server and using COM functions seems impossible, or very tedious at best.

  • I have looked at Aspose.Slides, which also seems rather expensive, and their documentation is filled with errors.

I could use suggestions on how to tackle this problem.

I have tried to find the underlying problem of why LibreOffice and online conversion tools have a problem with the backgrounds of the presentations I need to convert. The background is a .emf file, which has bad support.

My solution

I've unzipped the presentation, converted the .emf files to png (using ghostscript), changed all mentions of .emf to .png in the XML, and rezipped the altered presentation.

When I now use the LibreOffice headless to convert to pdf, the background shows up.

It might be a bit hacky , but it works for the intent of my program.


ps. I see that my question has gathered a few downvotes. In my opinion it was a valid question, and listed the various solutions that had worked for others, but not for me. If anyone has insights or ways to improve it, feel free to comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM