We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words Java with PHP/Java bridge

I’m trying to get Aspose.Words working with the PHP/Java bridge, and having no success. So far I’ve managed to get Tomcat installed on my Ubuntu box, along with the PHP/Java bridge. All of that is tested and working. I’ve also installed Maven, since it seems to be mentioned vaguely here and there in the documentation.

Unfortunately the documentation beyond that seems a bit lacking. There’s a page at https://docs.aspose.com/display/wordsjava/PHP+and+Aspose.Words+for+Java that includes an example that fails, because java_require is apparently no longer supported. It suggests using ‘tomcat or jee hot deployment’. So I assume that this guide must be out of date.

The other document I’ve been referring to is at https://docs.aspose.com/display/wordsjava/Installation and is entitled ‘Installing Aspose.Words for Java from Maven Repository’. The information here is very basic, and it starts off with ‘First, you need to specify Aspose Maven Repository configuration/location in your Maven pom.xml’… Now that’s all very well, but I don’t have a Maven project, or really any wish to learn all about Maven for this one piece of work. All I want to do is use Aspose.Words from my existing PHP project.

Can anyone point me towards what I need to do next? I have some code that looks like this:

require_once(‘http://localhost:8080/JavaBridge/java/Java.inc’);
$documentObject = new Java(“com.aspose.words.Document”);

The above just leads to the following error: “java.lang.Exception: CreateInstance failed: new com.aspose.words.Document. Cause: java.lang.ClassNotFoundException: com.aspose.words.Document”

I’m sure I’m about 90% of the way to getting this working. Just not sure what I need to do next. Unfortunately I know next to nothing about Java.

@pipeski

Could you please share PHP, Java and Tomcat version that you are using? We will investigate this issue and provide you more information on it.

We are working over this query and will get back to you soon.

If you do not want to use Maven, we suggest you please download Aspose.Words’ Jar file and include it into your project.

This exception shows that Aspose.Words’ classes are not visible to Java bridge. Please make sure that you are using the Aspose.Words’ Jar correctly.

Hi. It’s PHP 5.6.40 and 7.4.3. Tomcat 9.0.31. Java 11.0.6.

I followed the instructions here and placed the Aspose Words Jar file in a web application template, and then placed the .war file in the deployment folder. I now have an application listed in the Tomcat Web App Manager.

My PHP code is just based on one of the examples:

<?php
require_once('http://localhost:8080/JavaBridge/java/Java.inc');

// The path to the documents directory.
$dataDir = "/work/uploads/test/";

// Create a blank document.
$documentObject = new Java("com.aspose.words.Document");

// DocumentBuilder provides members to easily add content to a document.
$builderBoject = new Java("com.aspose.words.DocumentBuilder",$documentObject);

// Write a new paragraph in the document with the text "Hello World!"
$builderBoject->writeln("Hello World!");

// Save the document in DOCX format. The format to save as is inferred from the extension of the file name.
// Aspose.Words supports saving any document in many more formats.
$documentObject->save($dataDir . "HelloWorld.docx");
?>

@pipeski

It seems that you have resolved your issue. Are you still facing ClassNotFoundException?

Yes, I’m still seeing that exception.

@pipeski

We are working over your query and will get back to you soon.

@pipeski

We have logged this problem in our issue tracking system as WORDSJAVA-2329. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.