Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

calling an openoffice macro from php (exec)

Posted on 2008-06-19
3
Medium Priority
?
1,211 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 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

963 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