Solved

calling an openoffice macro from php (exec)

Posted on 2008-06-19
3
1,195 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now