Php and Slides Invalid document error Java.inc

HI,

I’ve been trying to make the examples work in the documentation regarding PHP and JavaBridge with no success. Even your documentation links are not working, so you may want to double check those. There are lots of dead end links/resources out there regarding php+aspose slides.

So, i’ve followed the instructions stated here: https://docs.aspose.com/display/slidesjava/Download+and+Configure+Aspose.Slides+in+PHP. It failed cloning the reposiroty, so you might want to fix that.

Then i’ve managed to move the Aspose_Slides_Java_for_PHP into the avaBridge folder manually, then copied aspose slides jar, and the 3rd_party folder (with it’s content) to JavaBridge/WEB-INF/lib folder. I’ve set the permissions on all files/folders (which your documentation doesn’t even mention), and when I navigated to url:8080/JavaBridge/Aspose_Slides_Java_for_PHP/tests/ it gave me an error message saying undfined $cancelProxyCreationTag in Java.inc. So I edited the Java.inc file, added the property to the relevant class and tried it again.

This time it complained about HelloWorld.pptx not existing ( This is the code i downloaded from the official repository). So i create an empty pptx file, name it, upload it, and try again. Wolaaa it works, ok good. Now, I comment all the example codes (keeping the impors at the top) and enable only:

print “Running Aspose\Slides\WorkingWithSlidesInPresentation\CloneSlides::run()” . PHP_EOL;
CloneSlides::run(DIR . ‘/data/WorkingWithSlidesInPresentation/CloneSlides/’);

It fails:

javax.servlet.ServletException: java.lang.RuntimeException: PHP Fatal error: protocol error: ,Invalid document end at col 14. Check the back end log for OutOfMemoryErrors. in /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc on line 870
PHP Stack trace:
PHP 1. {main}() /var/lib/tomcat8/webapps/JavaBridge/Aspose_Slides_Java_for_PHP/tests/index.php:0
PHP 2. Aspose\Slides\WorkingWithSlidesInPresentation\CloneSlides::run() /var/lib/tomcat8/webapps/JavaBridge/Aspose_Slides_Java_for_PHP/tests/index.php:155
PHP 3. Aspose\Slides\WorkingWithSlidesInPresentation\CloneSlides::clone_to_end_of_presentation() /var/lib/tomcat8/webapps/JavaBridge/Aspose_Slides_Java_for_PHP/src/aspose/slides/WorkingWithSlidesInPresentation/CloneSlides.php:14
PHP 4. com\aspose\slides\Presentation->__construct() /var/lib/tomcat8/webapps/JavaBridge/Aspose_Slides_Java_for_PHP/src/aspose/slides/WorkingWithSlidesInPresentation/CloneSlides.php:28
PHP 5. Java->Java() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc(64) : eval()'d code:1
PHP 6. java_Client->createObject() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:1930
PHP 7. java_Protocol->createObjectEnd() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:535
PHP 8. java_Protocol->finish() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:1315
PHP 9. java_Protocol->handle() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:1287
PHP 10. java_Client->handleRequests() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:1280
PHP 11. java_Parser->parse() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:348
PHP 12. java_NativeParser->parse() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:723
PHP 13. java_SocketHandler->shutdownBrokenConnection() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:702
PHP 14. java_SocketHandler->dieWithBrokenConnection() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:874
PHP 15. trigger_error() /var/lib/tomcat8/webapps/JavaBridge/java/Java.inc:870

php.java.servlet.fastcgi.FastCGIServlet.handle(FastCGIServlet.java:499)
php.java.servlet.fastcgi.FastCGIServlet.doGet(FastCGIServlet.java:521)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
php.java.servlet.PhpCGIFilter.doFilter(PhpCGIFilter.java:126)

So, in summary, it only works for very few of the examples, and there isn’t a proper example of how to set things up in the documentation.

My test environment is a vagrant machine running Ubuntu Server x64 16.04, php 7.0, tomcat8.

So any advices? I need to make this work, primarly merging powerpoint files and slides. I have like a few days before i can acutally tell the management that it works and then they can buy a licence.

Sorry for the long message.

The problem seems to be reading a file when instantiating the presentation object:

$pres = new Presentation($dataDir.'HelloWorld.pptx');php_slides_error.jpg (506.1 KB)

file_exists returns true, so the path is correct.

See attached image for the screenshot of the error message.

@msesen,

I have observed the stack trace image and your comments that example work for few examples. It is likely possible that you are probably loading a bigger file then set heap size on your end. Moreover, the stack trace does not mention any direct exception related to API as well. I suggest you to please try loading the presentation throwing exception in simple java console application to see if there is any issue with API while loading the presentation. If there is no issue while loading presentation in Java console application then it means that API has no issue while working with presentation and you may need to verify the settings on your end.

Thank you for the reply.

I have been trying for the last two days, but have the same problem. Could you please verify that you can successfully make the examples work on an ubuntu server 16.04, running php 7 with tomcat8? If yes, can you kindly please guide me for such a setup?

@msesen,

We require source presentation that you are using on your end and which is throwing issue. Please also share have you performed the suggested test to use Aspose.Slides for Java 18.3 on your end in simple Java application as well or not.

Thank you for replying.

The source presentation is the one created from the official HelloWorld example.
HelloWorld.zip (21.1 KB)

Yes, I successfully created and merged presentations using the java console.

We need to be able to run it on the web using PHP.

I’ve tried like 10 times, using different resources, and I just tried now using the following instructions:
PHP/Java Bridge, and your official documentation.

I always get : Fatal error: protocol error: ,Invalid document … Check the back end log for OutOfMemoryErrors. in http://localhost:8080/JavaBridge/java/Java.inc

This happens when i try to run your examples. I am starting to think that there are some incompatibilities somewhere because I can run the JavaBridge examples just fine.

As I said, if you can VERIFY that your examples run fine on Ubuntu Server 16.04, PHP 7, tomcat8, php-java-bridge-7.2.1 and guide me of your system setup, then we may be able to resolve the problem.

If not, I have to look for another solution. I can’t persuade the management to buy a licence without showing them a working example. We primarily need to merge presentation files, and create new presentation files from existing slides from multiple presentation files. And Cloud API is not an option.

@msesen,

I have set up PHP environment on my end using nginx server and PHP 5 in Windows 7 environment using Java Bridge option. Please visit this documentation for complete settings on your end and we follow and recommend customers to follow this on their end while setting PHP:
https://drive.google.com/open?id=1XVQ57zXGuycu3WUtOzb0rLl08ATtN_H8

Based on above article, I have setup this environment on my end and tested your presentation file:
https://drive.google.com/open?id=1eTnK2jQTKhTEeCbndEkp-T0JB3mRe2UW

There has been no issue on my end while reading your presentation and saving that. I hope the shared information will be helpful to you.

Thank you Mudassir, i will keep you updated.

@msesen,

You are very welcome. Please feel free to share, if you still find issue.

Just to keep this post updated for anyone, for the time being we are building a jar file and then use PHP’s shell_exec() function to execute the jar and pass a json encoded string as an argument that will contain all the necessary data, which will then be converted by Java etc, and do all the merging etc. So far it seems to be working.

I don’t think there should be any problems running java slides on a Linux environment, but just to make sure, are there any drawbacks that we need to be aware of?

Many thanks.

@msesen,

Aspose.Slides for Java is compatible to work in PHP environment using PHP Java Bridge. If you observe any issue feel free to share with us.

Thanks for your reply @mudassir.fayyaz. We are currently on a Linux Apache Tomcat environment. Any experience of similar environment?

Ok, it’s no worries, I have set up in a Linux Apache Tomcat environment. All I did was to follow the instructions here PHP/Java Bridge.

@JediJide,

It’s good to know that you have been able to configure the environment on your end. If there is still an issue then please share with us.