About News Downloads Installation Documentation FAQ Links Contact

Documentation


Installation

Instructions for downloading, compiling and installing are available at the Installation page.


General Programming Guidelines

The auxiliary function get_remote_xcomponent must be called before any other API or auxiliary method. This function initializes the "connection" to the Office and allocates any internal data required by the module.
It takes two parameters. The first, is the UNO URL and the second is the name of the "first service" to be created.
As a general guide, using the call bellow should be sufficient to get a valid connection to OpenOffice.
$var=get_remote_xcomponent(
"uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager",
"com.sun.star.frame.Desktop");

Puno uses the UNO Reflection API to access objects and execute methods from the OpenOffice.org API. It is important to note that PHP functions and methods names are case-insentive, but those accessed through the Reflection API are not. This means that you must always write objects names exactly as they are documented in the Developers Guide. This rule is valid for objects attributes and methods names as well.

API defined structs are also created through the Reflection API. For this purpose, the special function create_struct is available. It takes just one parameter, the name of the struct to be created.

Differently from Java and C++ bindings, in PHP it is not necessary to query interfaces from objects or services. This is automatically done by the Reflection API. So you just need to call the desired method from the object and the correct interface will be used.

IMPORTANT: As saw in the examples, the method dispose() must be called at the end of every script, otherwise the office running on the server may crash or become unstable.


Starting the Office

Follow the steps described in the OpenOffice Developers Guide to configure your office installation to listen on a TCP socket.

Or, the simplest way, just start the Office with the following line:
<OFFICEPATH>/program/soffice "-accept=socket,port=8100;urp;"

You can use the command "netstat -an | grep 8100" to identify whether the Office is listening on the TCP port or not.

OpenOffice.org must be configured with Java support enabled in order to receive TCP/IP connections.


Connecting

As said earlier, the connection to OpenOffice.org is made through an auxiliary function:
get_remote_xcomponent
It takes two parameters:

get_remote_xcomponent must be called before any other OpenOffice method or auxiliary function. This is necessary so it can initialize internal components used to create structs and other services instances.

Using the call as it's bellow is sufficient to get a valid connection to OpenOffice:
$var=get_remote_xcomponent(
"uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager",
"com.sun.star.frame.Desktop");


Creating Structs

Structs are also created through the Reflection API.

For this purpose, the special function create_struct is available.
It takes just one parameter, the full name of the struct to be created.

For example, if you need to create an instance of the struct TableBorder you must enter:
create_struct("com.sun.star.table.TableBorder");

IMPORTANT: struct names are case-sensitive.


Data Types Conversion

Simple types occur in structs, method return values or parameters. The following table shows the simple types in UNO and, if available, their exact mappings to Java, C++ and PHP.

UNO

Type description

Java

C++

PHP

char

16-bit unicode character type

char

sal_Unicode

String¹

boolean

boolean type; true and false

boolean

sal_Bool

Boolean

byte

8-bit ordinal type

byte

sal_Int8

Integer

short

signed 16-bit ordinal type

short

sal_Int16

Integer

unsigned short

unsigned 16-bit ordinal type

-

sal_uInt16

Integer

long

signed 32-bit ordinal type

int

sal_Int32

Integer

unsigned long

unsigned 32-bit type

-

sal_uInt32

Float²

hyper

signed 64-bit ordinal type

long

Float²

Float²

unsigned hyper

unsigned 64-bit ordinal type

Float²

sal_uInt64

Float²

float

processor dependent float

float

float (IEEE float)

Float³

double

processor dependent double

double

double (IEEE double)

Float³


¹ Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array-brackets like $str[2] so think of a string as an array of characters.

² The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers. If a number is beyond the bounds of the integer type, it will be interpreted as a float instead. Also, if you perform an operation that results in a number beyond the bounds of the integer type, a float will be returned instead.

³ The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (that's 64 bit IEEE format).


Full API Documentation

Full API documentation is available online at
http://api.openoffice.org/DevelopersGuide/DevelopersGuide.html

Almost all examples are written in and "for" Java, so you need to consider the General Programming Guidelines when translating Java examples to PHP.


Some Examples


Windows Users

On windows you can access the OpenOffice API using PHP's COM module.
If you wish to create fully compatible code between Windows and Linux/Unix, then you need to write the userspace auxiliary functions implemented by Puno. Also, constants like FontWeight_BOLD have to be defined before you can use them.
The file puno.inc contains all the code necessary to make your scripts portable between Linux/Unix (Puno) and Windows (COM). You just need to include it at the beginning of your files (Windows only).
In the code, the two auxiliary functions create_struct and get_remote_xcomponent are implemented as follows:
<?php
$GLOBALS
'__puno_srv_manager' ] = NULL ;

//get connection 
function get_remote_xcomponent$uno_url$first_service )
{
    
$srv_manager = new COM("com.sun.star.ServiceManager");
    
$GLOBALS'__puno_srv_manager' ] = $srv_manager;
    
$core_reflection $srv_manager->createInstance("com.sun.star.reflection.CoreReflection");

    
$GLOBALS'core_reflection' ] = $core_reflection;
    
$srv $srv_manager->createInstance$first_service );
    return 
$srv;
}

//create structs
function create_struct$name )
{
    
$srv_manager $GLOBALS'__puno_srv_manager'];
    
$new_struct $srv_manager->Bridge_GetStruct$name );

    return 
$new_struct;
}
// 
?>
Take a look at http://www.oooforum.org/forum/viewtopic.phtml?t=3474 for more information about PHP5/COM integration.

IMPORTANT: PHP's COM implementation seems to have a problem when dealing with Empty Arrays. For now, the only possible solution is to create an array with at least one element and fill it with an acceptable default value.


Basically speaking, on Windows, this code works:
<?php
    $load_url
="private:factory/".$doc_type;
    
$property create_struct"com.sun.star.beans.PropertyValue" );
    
$property->Name "ReadOnly";
    
$property->Value FALSE
    
$load_props = array();
    
$load_props[0] = $property;
   
$x_component_loader->loadComponentFromURL($load_url,"_blank",0$load_props);
?>

But this, with an empty $load_props, does not:
<?php
    $load_url
="private:factory/".$doc_type;
    
$load_props = array();
   
$x_component_loader->loadComponentFromURL($load_url,"_blank",0$load_props);
?>


SourceForge.net Logo