Solved

calling an openoffice macro from php (exec)

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

763 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

13 Experts available now in Live!

Get 1:1 Help Now