Solved

calling an openoffice macro from php (exec)

Posted on 2008-06-19
3
1,197 Views
Last Modified: 2013-12-13
Hi,

I have to call a openoffice-macro from PHP by using either exec or system.This is the code :

$cmd = '"c:\Program Files\OpenOffice.org 2.4\program\soffice" -invisible macro:///Standard.MyConversions.SaveAsPDF(c:\tmp\sample.doc)';

$lastLine = shell_exec($cmd);
echo "<br/><pre>$lastLine</pre>\n";
 
The command is all right, if I open a DOS-window and enter it the .doc file is created.
It is not a PHP-enviroment problem since I can call other commands in order to create files and other log-files and it works perfectly, like :

$cmd = 'dir c:\tmp > c:\tmp\dir.log';
$lastLine = shell_exec($cmd);
echo "<br/><pre>$lastLine</pre>\n";

The problem is that the process : cmd.exe -> soffice.exe -> soffice.bin just freezes, no error or whatever it is being logged.

I attached the Macro. Do you know the process freezes?

' Based on code from http://www.oooforum.org/forum/viewtopic.phtml?t=3772
 
' Save document as an Acrobat PDF file.
Sub SaveAsPDF( cFile )
   cURL = ConvertToURL( cFile )
   ' Open the document. Just blindly assume that the document 
   ' is of a type that OOo will correctly recognize and open 
   ' without specifying an import filter.
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
            Array(MakePropertyValue( "Hidden", True ),))
 
   cFile = Left( cFile, Len( cFile ) - 4 ) + ".pdf"
   cURL = ConvertToURL( cFile )
   
   ' 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
   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

Open in new window

0
Comment
Question by:SWB-Consulting
3 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 21824868
This is not my area of expertise. Using google I see some people using StarDesktop.terminate(). I am however not convinced that it is necessairy, although it might something that you could check out.
0
 
LVL 8

Assisted Solution

by:biztiger
biztiger earned 250 total points
ID: 23182255
Create another batch file, say a.bat. Now copy your command there. Call a.bat from php. It will solve your problem. You can pass variable value also to that batch file using "a.bat abc" and recieve it on batch file using %1 .
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question