Solved

calling an openoffice macro from php (exec)

Posted on 2008-06-19
3
1,205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

729 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