Calling macro in shell_exec not working

Hi guys! I really need your help.
I have a php code that should convert doc, ppt,etc. to pdf using openoffice. But its not working, and im not sure what the problem is.

Here's my php code:

define('OOFFICE_LIBRARY', '/usr/lib/openoffice.org/program/');
$convertToPdf = OOFFICE_LIBRARY . 'soffice -invisible -headless -norestore "macro:///Standard.Module1.SaveAsPdf("' . $fileSourcePath . '")"';
shell_exec($convertToPdf);

the above command works fine when run directly on the command line, but when used in php code, its not working.

and here's my macro:

Sub SaveDocAsPdf ( cFile )
	Dim oDoc as object
	
	cURL = ConvertToUrl ( cFile )
	
	oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(MakePropertyValue( "Hidden", True ),))
	
	cFile = Left( cFile, Len( cFile ) - 4 )
	cURL = ConvertToURL( cFile + ".pdf")
	
	
	'Save the document using a filter.
		oDoc.storeToURL( cURL, Array( MakePropertyValue( "FilterName", "writer_pdf_Export" ) ) )
		
	oDoc.close( True )
End Sub

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
	' oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
	Dim oPropertyValue As New com.sun.star.beans.PropertyValue
	If Not IsMissing( cName ) Then
		oPropertyValue.Name = cName
	EndIf
	If Not IsMissing( uValue ) Then
		oPropertyValue.Value = uValue
	EndIf
	MakePropertyValue() = oPropertyValue
End Function

I created the macro using the user 'root'. Through the command line, I used the "soffice " command that launches the openoffice. Btw, Im using a linux-php environment.

Hope someone could help me with this. Been trying to figure this out for days. :frowning: Thanks a lot.

Please describe this "doesn't work" in more detail.

You may need to check and make sure soffice is in your PATH, the path a webserver gives you may be far more minimal than you'd get running it in your own personal shell.

Also check the permissions of the macro file you're trying to use. Just because you can access it doesn't mean a CGI script can.

Hi! Thanks for the reply! :slight_smile: What i means by "doesn't work" is that its not converting the doc file i've uploaded to pdf file.

Regarding the permissions of the macro file, what should that be? I created the macro file by logging in as 'root' in the command line, launching open office by typing 'soffice', and then directly creating the macro by clicking tools>macros>organize macros>OpenOffice.org basic. And that's it. Should I create the macros using any other accounts?

Sorry, Im still a newbie regarding these macro, openoffice and linux stuff.. :slight_smile:

Well, obviously. But what does it do? Does it print any error messages?

Depends what you want to be able to read it. You haven't told me exactly what you're doing as who so that's hard to just guess.

You need to create yourself a real user account ASAP. You can't just go around running ordinary applications as root all the time, that's dangerous.

Your macro file probably can't be read by anything but root. Try listing the permissions on it with ls -l filename

It doesnt do anything. After clicking the upload button, the .doc file just uploads, but not converted. It reloads the page. Also, it doesnt display any errors.

Then i guess the permission of the macro file should be executable by the apache or non-root users? since the user that runs the php is Apache?

Yes I already have my own user account. Should the macro file be created using my account or other accounts other than the root? What would be the difference if the macro is created not using the root account?

Sorry for too many question.. :frowning:

---------- Post updated at 03:48 AM ---------- Previous update was at 03:28 AM ----------

Followup question. Im not sure which is the macro file.. Is it the "Module1.xba" file? Thanks! :slight_smile:

That doesn't matter so much, either way you'll need to do something to let apache be able to read it. The point is to not do it as root.

The difference is that, when running it as root, you're running it as root, and by doing so, allowing ooffice unimpeded access to absolutely anything in the system whatsoever. If it decides to open your disk device and muck it up, it can. You're not protected from any mistakes, be they yours or by the programmers of ooffice.

You know more about your macros than I do. I'm still not 100% sure that's even the problem. Did you correct your PATH?

Try grepping for MakePropertyValue to find out what file it's in. If it's in a config file in your home directory, ooffice probably won't have any idea where to look for it when not logged in as that user, so won't find it at all, you might have to force it into loading external macros somehow or set HOME to a fake value.