posts - 7 , comments - 67 , trackbacks - 0

Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Ok, so I needed to convert .docx files to .pdf files on the fly, but none of the free php libraries that were available let me do it on my server (a webservice was not good enough).

Basically either I needed to pay for a library (and have it maybe suck) or just deal with the free ones that didn't convert the formatting well enough.

Not good enough!

I found that LibreOffice (OpenOffice's successor) allows command line conversion using the LibreOffice conversion engine (which DID preserve the formatting like I wanted and generally worked great).

I loaded the latest version of Ubuntu (http://www.ubuntu.com/download/ubuntu/download) onto my Virtual Box (https://www.virtualbox.org/wiki/Downloads) on my computer and found that I was able to easily convert files using the commandline like this:

libreoffice --headless -convert-to pdf fileToConvert.docx -outdir output/path/for/pdf

I thought: sweet...but I don't have admin rights on my host's web server. I tried to use a "portable" version of LibreOffice that I obtained from http://portablelinuxapps.org/ but I was unable to get it to work on my host's webserver, because my host's webserver didn't have all the dependencies (Dependency Hell! http://en.wikipedia.org/wiki/Dependency_hell)

I was at a loss of how to make it work, until I ran across a cool project made by a Ph.D. student (Philip J. Guo) at Stanford called CDE: http://www.pgbovine.net/cde.html

I will let you look at his explanations of how it works (I followed what he did here:

starting at about 32:00 as well as the directions on his site), but in short, it allows one to avoid dependency hell by copying all the files used when you run certain commands, recreating the linux environment where the command worked. I was able to use this to run LibreOffice without having to resort to someone's portable version of it, and it worked just like it did when I did it on Ubuntu with the command above, with a tweak: I needed to run the wrapper of LibreOffice the CDE generated.

So, below is my PHP code that calls it. In this code snippet, the filename to be copied is passed in as $_POST["filename"]. I copy the file to the same spot where I originally converted the file, convert it, copy it back and then delete all the files (so that it doesn't start growing exponentially).

I did it this way because I wasn't able to make it work otherwise on the webserver. If there is a linux + webserver ninja out there that can figure out how to make it work without doing this, I would be interested to know what you did. Please post a comment or something if you did that.

<?php
//first copy the file to the magic place where we can convert it to a pdf on the fly
copy($_POST["filename"], "../LibreOffice/cde-package/cde-root/home/robert/Desktop/".$_POST["filename"]);
//change to that directory
chdir('../LibreOffice/cde-package/cde-root/home/robert');
//the magic command that does the conversion
$myCommand = "./libreoffice.cde --headless -convert-to pdf Desktop/".$_POST["filename"]." -outdir Desktop/";
exec ($myCommand);
//copy the file back
copy("Desktop/".str_replace(".docx", ".pdf", $_POST["filename"]), "../../../../../documents/".str_replace(".docx", ".pdf", $_POST["filename"]));
//delete all the files out of the magic place where we can convert it to a pdf on the fly
$files1 = scandir('Desktop');
//my files that I generated all happened to start with a number.
$pattern = '/^[0-9]/';
foreach ($files1 as $value)
{
preg_match($pattern, $value, $matches);
if(count($matches) > 0)
{
unlink("Desktop/".$value);
}
}
//changing the header to the location of the file makes it work well on androids
header( 'Location: '.str_replace(".docx", ".pdf", $_POST["filename"]) );
?>

And here is the tar.gz file I generated I generated with CDE. See below for a working example and complete, documented code.

Success! I made a truly portable version of LibreOffice that can convert files on the fly on a webserver using 100% free, open source software!

Note: since when I used CDE I only converted a .docx to a .pdf, my tar.gz file above will probably only work to do that. To get it to do other things, you will have to do them with CDE first.

*****************************************************************************

UPDATE: since several people have had questions on how to get it working or had issues making it work, I am putting a complete working example out there for you to play with and modify.

Click here for working example.

And here is the tar.gz of the working example, tied up in a nice bow for you. To make sure the permissions don't get screwed up, I recommend uploading the tar.gz file to your server and then unpacking it there.

This is my way of giving back to all the great people out there that have helped me out by doing these kinds of things for me. Pay it forward, guys! [licensed under the MIT license.]

Print | posted on Saturday, November 19, 2011 6:07 PM |

Feedback

Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi,

I've got this error:

$ ./libreoffice.cde --headless -convert-to pdf Desktop/test.docx -outdir Desktop/
ELF binary type "0" not known.
../../../cde-exec: 1: Syntax error: "&" unexpected (expecting ")")


Could you help me with this?

Best regards
12/14/2011 10:36 PM | Adam
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Thanks for this, I too have a shared server (with 1and1). I managed to package up LibreOffice to process .doc, .docx, ppt and pptx files and convert them to PDF. I can ssh into the server and the commands all work fine. However, when I use exec, or shell_exec, nothing happens! I don't even get an error message. Everything seems fine, it just doesn't create the PDF file at the end of it. Did you have any problems with your shared hosting?
1/8/2012 11:39 AM | tricky
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Try adding "-nologo -nofirststartwizard"(omitting the quotes ;) ) to the parameters... That did the trick for me on my box even though I run it in bash rather than via a php file..
1/10/2012 7:50 AM | Niels
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Great article! :) I've been playing around with this and it seems to work well, but there are two questions I have.

I can convert the first page of a TIFF file to a PDF, but how do I read all pages?

What do I need to install to get it to output a TIFF file?

No worries if you don't know, but if you could help me out with those two points I'd be very grateful :)
2/1/2012 7:04 AM | Paul
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I can only convert to PDF and not HTML.

convert /tmp/math.docx -> /tmp//math.html using XHTML Writer File
Error: Please reverify input parameters...

Have you made any hardcoding in the CDE for PDF?
2/29/2012 7:56 AM | Vs
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

To convert to something other than a PDF (like a TIFF or HTML), you will need to redo the CDE steps with libre office or some other program in linux that can convert like you want it to.
The tar.gz file I have hanging on the server above was specifically geared towards converting to a .PDF
2/29/2012 8:22 AM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi, Can you please make CDE for HTML
Thanks
2/29/2012 9:12 AM | Vs
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

do you use a portable version of Libreoffice ?

I could find only a 32bit version of the portable version of Libreoffice for linux, and my server runs on 64bit..

I tried to use CDE with the installed version of libreoffice, when I use exec(..), it fails and the return code is 77 (which I couldn't find the meaning...).

Any suggestion ?
3/13/2012 3:28 AM | kamel
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

No I didn't use the portable version of Libreoffice.

I made a CDE version of libreoffice in linux and used that instead. I recommend you just use the tar.gz file I have at the end of my article and follow my directions to get that working.

I hope that helps :)
3/13/2012 10:23 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I finally made it work. the return code 77 meant my php script didn't have permissions to execute the handler libreoffice.cde.
So I changed the owner and group of the folder cde-package to www-data, and it works perfectly. You can see a demo here : http://www.flexilivre.com/doc/

Thanks a lot !
3/14/2012 1:37 AM | kamel
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

That is awesome! I am glad that it helped you out!

This article is my way of giving back to all the awesome articles and open source tools and such that folks have put out there. Hearing that it made your life easier makes me happy :)

3/14/2012 7:05 AM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

How to convert docx to pdf without color ?
3/30/2012 3:22 AM | Yau Tee Kuan
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi there,

I am trying to use libreoffice to convert docx to pdf from PHP. I have used the following command. I am using Ubuntu linux with Apache.

$myCommand = "/usr/bin/libreoffice -headless -invisible -convert-to pdf {$file_name} -outdir /www-disk/temp/";
exec($myCommand, $output, $ret_var);

I have set the permissions for the user www-data as below:
chown www-data:www-data /usr/bin/libreoffice
chown -R www-data:www-data /usr/share/libreoffice/

The file is not getting converted when I run it through php.

When I run from the command prompt it did convert perfectly.
One thing I noticed. After running the above command there is another command automatically popped out in the terminal as:

# convert ...filepath.docx -> ...filepath.pdf using writer_pdf_Export

Thanks for your help in this...
4/4/2012 2:26 AM | Hameed
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Dear Robert,

Any suggestions from your side? It would be an immense help actually for us here.

Thanks a lot!


4/6/2012 12:43 AM | Hameed
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Have you checked to see if PHP has permissions to execute any command with exec(), like just to rename a file or something? Since the command works from the command line, it should work from PHP as long as PHP is properly set up and updated.

I hope that helps!

Robert
4/10/2012 8:08 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi there,

I'm uploaded your files to my server and tried to change them accordingly but I am however running into a roadblock.

When executing:

$myCommand = "./libreoffice.cde --headless -convert-to pdf Desktop/".$document." -outdir Desktop/";

I am told ../../../cde-exec: not found

Any thoughts?
4/12/2012 2:43 PM | adjarbde
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

The code above does work.

I have made it work successfully on two different servers (and when it came time to make it work on the 2nd server, I actually went back and copied my code from this article to make it work), and have had several people thank me for it after they were able to get it to work.

This means that, assuming you have properly extracted the tar.gz file above and are running a somewhat updated LAMP server with a somewhat normal set of web server settings, you must be trying to call the command from the wrong directory.

I hope that helps. If I get some time this next week, I will make a working example project and upload it to my server and put a link to the code here in this article.

Robert
4/17/2012 4:18 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I put a working example of it on my server, and included the code for it. See the update. I hope that helps.

Do great things and pay it forward! :)

Robert
4/17/2012 8:49 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Thanks for putting so much effort into this, I've currently got my setup successfully converting from docx to PDF. My only question for you is that it seems the fonts in my word documents get screwed up in the conversion process.

I downloaded & installed the Microsoft Core Fonts and even got the Microsoft Vista fonts but there doesn't seem to be any effect. Any tips or ideas on what to do with that?
4/19/2012 1:16 PM | Jeffry56
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

You are welcome!
Well, as far as the font conversion is concerned, it is only going to be as good as the fonts on my ubuntu/libreoffice combination that I used when I made the CDE libreoffice portable that I used in it. I didn't load any special fonts because I didn't need them.
To fix this, I suggest that you fire up linux, install libreoffice, make sure all your fonts appear in your libreoffice, then convert it once on the command line with CDE, like I did, (see the instructions above and CDE website) then replace the LibreOffice folder in my example with your copy of LibreOffice that CDE kicks out, being sure to adjust folder names as necessary.
I believe that will fix your problem. I hope that helps.

Robert
4/19/2012 1:25 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Thanks for this helpful article.
But I'm on Windows, I've installed LibreOffice and tryied conversion manually form the GUI, it works fine.
But the command line "soffice --headless -convert-to pdf M:\DataMourad\EnvDev_VB\CoursVB\AdoNet.docx -outdir M:\DataMourad\EnvDev_VB\CoursVB\" dont work yet.
Can anyone tell me what I must to do ? Is CDE nessecerlly for using the code Php.
Thanks a lot for your help.
4/27/2012 3:26 AM | Mourad
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hello,

Thanks for this helpful article,

I created a cde to convert doc to pdf and docx to pdf and uploades it to my shared server used the command
"$myCommand = "./libreoffice.cde --headless -convert-to pdf Desktop/".$_GET["filename"]." -outdir";
exec ($myCommand);"

to convert pdf but nothing happening,

But when i uploaded your example cde it working fine, i firstly think my cde package is the problem but i tried the package on other local machine it works fine..
Any idea why is that ??
5/26/2012 8:18 PM | ajith
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

To Mourad: If you are on windows, you should try to get something Microsofty to to this. It will be a lot easier, since CDE is meant to work on Linux, a completely different operating system. Be prepared to pay for it though.

To Ajith:
two things to look out for that will probably help you out:
1) did you unpack it on your server? When I tried to unpack it elsewhere and transfer the files one by one, it didn't work because the permissions got screwed up.
2) have you tested your command on the command line before trying it in PHP? Make sure that the command works before you have PHP invoke it, or it will never work right.

I hope that helps!

Robert
5/27/2012 12:10 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hello Robert,

i unpacked the files at the server,
but i didint checked it in the command line, how can i do that ? i have only access to c-panal.
5/27/2012 3:00 PM | Ajith
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hello Robert ,

Checked my cde package , when i try to convert the doc to pdf it will gives a messege Like "strace: exec: Bad address "
Any Idea why is that happening ?
is this a problem of Linux version? or Kernal version?
am using Ubuntu 12.04.
In which Os did you create the cde package ??
5/29/2012 11:35 AM | Ajith
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I came across a similar problem trying to get lowriter to work from PHP. export home=/tmp before calling the command and I was good to go.
7/26/2012 10:08 PM | rapid
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

When used below command on the command line it working file

libreoffice --headless -convert-to pdf ".$sourse." -outdir outputolder/

but, if use in php script nothing happen. can anybody provide what is exactly issue with the above command.
9/20/2012 1:21 AM | Ashish
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi i can't download the portable app can any one give it to me ???
11/18/2012 10:55 AM | mahmoud Saad
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

@Mahmoud: there never was a 'portable app'; I think you misunderstood what I am doing here.

@Ashish: I recommend you download my example project and start from there.

@Ajith: It sounds like you may want to use CDE on your own linux box, starting from scratch, using the instructions that Philip Guo and I provided on how to do it...you shouldn't have to, though. Check through everything I said carefully. You are probably skipping something important.
11/18/2012 11:24 AM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I need to convert doc file to html ,
can any please give me its CDE.
I am successfully running it for doc to pdf but my requirement is only doc to html or pdf to html
Thanks
Ajay
11/20/2012 5:04 AM | ajay
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

@Ajay

Dude, seriously? You actually expect me to just up and do work for you for free that someone is paying you to do?

I have already more than helped you with this tutorial, explaining what I did here. Follow the steps outlined above to make your own CDE by converting a doc to html the way you want it to work on the command line with some sort of a program (maybe libreoffice will work for you, maybe you will want to use something else) and then use the files CDE produces instead of the ones I provided.

If you follow all the instructions well, it will work perfectly.

Good luck.

Robert Hyatt
11/20/2012 10:29 AM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi!

For those who can not convert doc to pdf files from php using libreoffice and shell_exec or exec, take a look to:

https://github.com/mirkonasato/pyodconverter

This solved my problem.
12/19/2012 1:27 AM | Adrian
Gravatar

# re: Converting .pdf to docx (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

hi everyone!!

anyone can help about my problem about the code that giving this article??can i do the conversion using that code but there are a problem he output is corrupt. wat can i do? plz help me.thankx for your helping me!!
1/26/2013 6:30 AM | avlis leamse
Gravatar

# re: Converting .pdf to docx (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php



anyone can help about my problem about the code that giving this article??can i do the conversion using that code but there are a problem he output is corrupt. wat can i do? plz help me.thankx for your helping me!!
1/26/2013 6:32 AM | avlis leamse
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

@Avlis: What do you mean that you can 'do the conversion' using the code but that the output is corrupt? You are being extremely vague here.

I already went to the trouble of posting the code to a working example and including a link to it on my server. Everything works just fine. Professional software developers (the intended audience) have already been able to easily take what I have posted and run with it.

Like I told Ajay, I am not doing free work for people. If someone wants to pay me to do some work on the side for them, I would be happy to discuss it.

The purpose of this article is to give back to the community so that if someone wanted to duplicate what I did to use PHP to convert office documents on the fly (or even extrapolate what I did to interact with a linux command line application) they would have enough information to go to work.

Also, I recommend running your posts through a spelling/grammar check before posting in the future. Trying to decipher your spelling and grammar distracts from what you are trying to say.

Sincerely,

Robert
1/26/2013 9:23 AM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi!
Thanks for this helpful article,
Robert ,Really thanks.
I unpacked the example.tar.gz at the server it work for docx to pdf but when i try to doc to pdf or an other formats it not answered, does it have any point ???

permission of example code is 0777.

special thanks;
2/19/2013 1:21 AM | saeed
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hey @tricky ... did you ever manage to get this working on 1and1? When i run it, i get
Warning: copy(Desktop/1363051962example.pdf) [function.copy]: failed to open stream: No such file or directory in /homepages/38/d95209348/htdocs/hosted_sites/sppc-session/convertdoc/documents/phpdocx.php on line 34

No PDF is ever created...and thus the file is not found and cannot be copied to the new location. I have modified nothing, and untarred the file using SSH directly on the server, so permissions should be okay... I did try another copy of these files in another place and did some testing int eh code to try to find the issue, but am hitting a wall. I bet that 1and 1 is simply blocking it for some reason on their shared environment...but if you ever found a solution, please let me know!
3/11/2013 7:37 PM | CraigW
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

There was a problem during extracting zip files. I hope you can post new copy, When i extract it there was a corrupt files that makes the example doe'snt work at all.

Hope u can help me...

Thanks,
3/11/2013 7:54 PM | Meffrey
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

@Saeed--When I built my CDE version of libreoffice, I only ran the command to convert docx to pdf, so only the libraries that were used to make that conversion were built into it. If you want to do other file conversions, you will need to run CDE to make your own portable version of libreoffice. Run all the conversions you want it to support while building CDE. Use that version and it should work fine.
@CraigW--After setting it up,I recommend trying it from the command line first. It should work since the entire required environment is packaged up with CDE. Once you get it working from the command line, try getting it to work with your code. My example project is a good place to start.
@Meffrey--Copy the file to your server and unpack it there. The file works fine. I have used that file to add this functionality to a project I needed it for after writing this article, and so has a number of other people who have emailed me to thank me for what I did here.
3/11/2013 9:12 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I'm getting the error:
/usr/bin/stat: cannot read file system information for '/home/robert': No such file or directory

When running directly from SSH.

What am I doing wrong here?
3/21/2013 10:14 PM | Austin
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

It sounds like you are pointed at the wrong directory or that you never unpacked my tar.gz. Check to make sure that your current working directory is at the right spot and that you unpacked my tar.gz correctly.
3/21/2013 10:56 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

unpacked with command:
tar -xzf example.tar.gz

pwd shows:
/var/chroot/home/content/83/10729983/html/myusername/LibreOffice/cde-package/cde-root/home/robert

Should I be running from elsewhere?
3/21/2013 11:55 PM | Austin
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

If you are running from the command line, that should be the right spot. Is libreoffice.cde in that directory? Did you have any errors unpacking?
3/22/2013 6:44 AM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I also got a not found error message.

mengine@ubuntu:~/Downloads/LibreOffice/cde-package/cde-root/home/robert$ ./libreoffice.cde --headless -convert-to pdf topdf.docx -outdir Desktop/
./libreoffice.cde: 2: ./libreoffice.cde: ../../../cde-exec: not found

Any ideas?
3/26/2013 3:18 AM | Vegard Torvund
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Vegard Torvund: run "ls ../../../" and see what it returns. Do you see cde-exec?

Robert:
libreoffice.cde is in there. The really bizzare thing is that it works in the PHP script, but not direct from the shell. I put some debugging into the PHP script, and I see that it sees the directory that it's in differently, appearently my webhost puts you through a symlink when you SSH in, but I moved to the dir PHP was using and still got the same effect.

Didn't expect it to be much different, because the libreoffice.cde file uses a relative link to the cde-exec anyways, and that's not where the error was coming from.

You can see the output from my debugging from PHP at http://jemstest.org.previewdns.com/convertpdf.php

First line is the command being run, 2nd is the dir it's in, and 3rd is the output of it.

Overall though, the issue is that /usr/bin/stat (which is running from within the recreated CDE filesystem) is looking for /home/robert, and doesn't see it.
3/29/2013 7:44 PM | Austin
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hi, thanks for your answer:

this is the output:
cde-exec cde.full-environment cde.log cde.options cde-root cde.uname libreoffice.cde vegard.docx
4/23/2013 6:03 AM | Vegard Torvund
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I'm trying to to download the the example and complete application but both of them showing "This Account Has Been Suspended" in the given link.

Can you please reffer any other place where can i get the code or if possible you can email me. - sufean (at) gmail . com

thanks
5/1/2013 2:37 AM | Fean
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Sorry about that Fean. Please try again--the bill to renew my hosting subscription was sent to the wrong email, so there was a brief lapse.
5/2/2013 8:40 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

is it possible to convert pdf to doc file?
5/14/2013 2:14 PM | agent48
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

Hello! First of all, thanks for the work. I have a little problem when I try to execute the libreoffice.cde:
"SyntaxError: Parse error docx../cde-exec: libreoffice: command not found (path_to_search=/path-to-server/LibreOffice-cde/LibreOffice/cde-package/cde-root/usr/games/libreoffice)"
Could you help? Thanks
7/24/2013 6:32 AM | DusT
Gravatar

# Install on XAMPP, partially working but no pdf generated

Hi Robert!
Thank you very much for this work! It does excatly what I need, if libreoffice is able to hadle a very complex doc docx file (not long, but very complex tables, borders and line drawings).
I am trying to install your demo in XAMPP. The docx file is correctly generated with the custom text, but the pdf is not genrated. The browser just can't find the file (it is not pressent in the document folder).
Thre is no error report.
Any idea about what should I do?
Thaks in advance.
Alberto
9/19/2013 4:43 AM | Alberto
Gravatar

# Unable to convert a newly uploaded file

Hi Robert!
I'm trying to convert a docx file i uploaded through the php file upload method. I have replace the code accordingly. However it doesn't seem to work in this case and i am not thrown an error either.
Any idea about what should I do?
Thaks in advance.
Sumanth
10/7/2013 4:43 AM | sumanth
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

hi man

great efforts in this. but here is my situation

i am on windows with XAMPP as Apache. so is it possible generate my own CDE
and then upload to my shared hosting

i am totaly got no expernce with Linux commands
so can you instruct me how to mange this

thx
11/21/2013 3:46 AM | ahmed m
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

@agent48 please see my comment to Saeed on 3/11/2013
@DusT, have you tried untarring what I sent and executing it from the command line?
@Alberto, Please get it to work from the command line first. You will see the errors that you wouldn't see otherwise when you do that.
@sumanth, Again, please get it to work from the command line first.
@ahmed m, to generate your own CDE, I recommend downloading virtual box and ubuntu (or some other distribution if you prefer) and then following the rest of my steps I outlined in my article. Once you do that, you can take your CDE that you generated, tar it up, put it on your server and then untar it. The rest of the steps should work for you.
3/25/2014 9:13 PM | Robert Hyatt
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I want to convert the doc file to pdf. I upload your code on my server but but displaying error like "copy(Desktop/1410787898example.pdf) [function.copy]: failed to open stream: No such file or directory in ~/PDFEXAMPLE/documents/phpdocx.php on line 34"
9/15/2014 7:33 AM | Shailendra Ram
Gravatar

# re: Converting .docx to pdf (or .doc to pdf, or .doc to odt, etc.) with libreoffice on a webserver on the fly using php

I want to convert the doc file to pdf. I upload your code on my server but but displaying error like "copy(Desktop/1410787898example.pdf) [function.copy]: failed to open stream: No such file or directory in ~/PDFEXAMPLE/documents/phpdocx.php on line 34"
So please help me. What I have to do to run this.
9/15/2014 7:35 AM | Shailendra Ram
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: