PHP and PDF

The following code shows how webPDFs "converter" web service (OOoConverter) can be accessed from PHP 5. The code is based on the assumption, that the webPDF server is running on the same machine on which the PHP file is being executed. A graphics file "file.jpg" is being converted that is located in the same directory as the PHP file.

The code is intended for demo purposes only and has to be adapted to local requirements.
 

<?php
$input_file = 'file.jpg';
if(file_exists($input_file)) {
    $client = new SoapClient ( "http://localhost:8080/webPDF/OOoConverter?wsdl", array () );
    $avail = $client->__getFunctions ();
    $fh = fopen ( $input_file, 'r' );
    $data = fread ( $fh, filesize ( $input_file ) );
    fclose ( $fh );
    try {
        $test = array ('sourceExtension' => '.jpg', 'targetExtension' => '.pdf', 'options' => '', 'fileContent' => $data);
        $response = $client->convertSimple ( $test );
        file_put_contents ( './output.pdf', $response->return );
        echo "Convert successfull <br>";
        echo "<a href='output.pdf'>File</a> ";
    } catch ( Exception $e ) {
        $error_code = $e->detail->OOoConverterException->errorCode;
        $error_message = $e->detail->OOoConverterException->message;
        echo "ERORR CODE: " . $error_code . '<br />';
        echo "ERORR MESSAGE: " . $error_message;
    }
} else {
    echo 'Input file does not exist';
}
?>