0

Is there any way to convert xlsx, docx and pdf files to image(jpg) format programtically using PHP? I need to read this files from a server and convert them as images and show on page.

Thanks in adv

vamsi
  • 1,488
  • 3
  • 28
  • 66

1 Answers1

2

If you want to achieve this you must first convert your xlsx or docx to pdf

The best way to do it is to install libreoffice on your server.

Then use the headless command of libreoffice to perform the conversion to pdf

shell_exec('libreoffice --headless -convert-to pdf fileToConvert.docx -outdir output/path/for/pdf');

Then convert your pdf to jpg

shell_exec('/usr/local/bin/convert myfile.pdf myfile.jpg ');
BentoumiTech
  • 1,627
  • 14
  • 21
  • or else can I use the google doc viewer to render the files from there into my webpage? will this be a good idea? – vamsi Mar 16 '15 at 14:04
  • @vamsi It depend on what you lookin for, personally I rather prefer using offline API when I have the possibility. Why for example if google decide tomorrow to make user pay for each rendered file from google doc .... – BentoumiTech Mar 16 '15 at 14:31
  • @vamsi if you want to use the google doc viewer to render the files, you could as long as the files are publicly accessible - for more info, check out [this post](https://stackoverflow.com/a/17849382/1575353). – Sᴀᴍ Onᴇᴌᴀ Nov 13 '17 at 19:45