Aspose.Slides for PHP

Dear all, I’m new to the forum. This might have been asked before, but I just thought to drop my question here, if already covered, I would appreciate if someone could put the link below.


My question is that can we use the aspose.slides in the PHP environment? Our server uses Linux.

Many thanks in advance!

Hi Sheng,

Thanks for your interest in Aspose.Slides.

I have observed your requirements and like to share that Aspose.Slides does support working with PHP. I suggest you to please visit the guidelines shared in this thread link for your kind reference in this regard. Please share, if you need any help in this regard.

Many Thanks,

Thanks for your reply.


I have looked through the link you sent me, I cannot seem to find the instruction for converting PPT file to image.

Can you point me to the right direction please?

Thanks,
Sheng

Hi Sheng,

I have observed your requirements and like to share that you can convert slides to image in PHP environment using Aspose.Slides. I suggest you to please try using the following sample code on your end to serve the purpose. I hope the shared information will be helpful.

<?php
try
{
//Instantiate a Presentation object that represents a PPT file
$pres= new Java("com.aspose.slides.Presentation", "C:\\demo.ppt");

//get last position of presentation
$lastSlidePosition = $pres->getSlides()->getSlides()->size();

//iterate all slides
for ($pos = 0; $pos < $lastSlidePosition; $pos++)
{
$slide = $pres->getSlides()->get_Item($pos);
//Creating the Dimension object to specify the width and height of image
$dimension=new Java("java.awt.Dimension",720,540);

//Getting the thumbnail image of the slide of a specified size
//$image=$slide->getThumbnail($dimension);
$image=$slide->getThumbnail(1.0f,1.0f);

//Creating the ImageIO class object
$ImageIO = new Java("javax.imageio.ImageIO");

//Creating a file output stream to write the slide thumbnail
$fostream=new Java("java.io.FileOutputStream","C:\\thumbnail2.jpg");

//Saving the thumbnail image in jpeg format
$ImageIO->write($image,"jpeg",$fostream);
}
}
catch(JavaException $ex)
{
echo $ex;
}
?>

Many Thanks,

Hi Mudassir,


Thanks for your reply.

We tried this method but still getting error message. I’d wondering if you could help us.

Many thanks!

Sheng


Hi Sheng,

I have observed the information shared by you but unfortunately unable to understand what issue is incurring on your end. Please share the detailed information along with sample project and source presentation. Is the issue you are having is related to Aspose.Slides? Please share the issue details with us so that I may help you further in this regard.

Many Thanks,

Thanks Mudassir!

Hi Sheng,

I have observed the stack trace. Can you please make sure if your Java bridge has been successfully created in your PHP application. You can test this simply by using following statement.

$pres= new Java(“com.aspose.slides.Presentation”);

If this executes fine then it means your Java bridge is configured properly with Aspose.Slides. However, if the above empty Presentation class constructor throws exception then you need to check your environment that if that is properly configured and Aspose.Slides for Java is getting properly referenced.

If the above test pass then I suggest you to please first try using the desired code for creating image from slides in a console java application to see if there is any issue with API when dealing with source presentation. I also suggest you to please try using Aspose.Slides for Java 16.5.0 on your end.

Many Thanks,

Dear Mudassir,


Again thanks for your reply.

We have reexamined our configuration and finally are able to get this working to an extend.

Right now, we are able to convert this first page of a PPT file into a jpg file, but nothing happens to the rest pages of the file.

We suspect that there’s something wrong in the code that you sent to us in your earlier thread. Would you mind taking another look to confirm this for us please?

In the meantime, we will also go through our code as well.

We would really appreciate your swift reply.

Thanks,
Sheng

Hi Sheng,

I have checked the sample code shared by you and like to share that you are saving the same file for every slide thumbnail in your sample code shared here. You need to change the following sample code in your application with some different name every time.

$fostream=new Java(“java.io.FileOutputStream”,“/Users/user/Downloads/thumbnail2.jpg”);

You are saving every slide thumbnail with thumbnail2.jpg. Please revisit this line with some incremental file name on your end.

Many Thanks,

Hi Mudassir,

We are almost there now.

Many thanks,
Sheng

Hi Sheng,

I have observed the sample code and suggest you to please try replacing the following sample code in your code. I hope this will be helpful.

$ImageIO->write($image,“png”,$fostream);

Many Thanks,

Hi Mudassir,


We made the change to our code but still seeing no luck.

Rather than keep on populating this thread, I wrote you an email instead. Please check if you have received it.

Thanks,
Sheng

Hi Sheng,

I have observed the stack trace shared by you and have observed following exception.

“Cannot find any fonts installed on the system”.

This means that you are probably having missing fonts on your deployment server or if they are there you don’t have permissions for that. You your self have mentioned that same code works fine on Windows or Mac on your end.
Please check the permissions and grant appropriate permissions. If the fonts are missing, you can copy the used fonts in target server at some location and load the fonts externally using Aspose.Slides for Java without even installing them. I hope this will be helpful.

Many Thanks,

Hi Mudassir,


Good news, after adding the front it’s at least working on one of our Linux servers, but we are still seeing some error messages on the other two, even though they have exactly the same configuration. We are still working to fix it.

On a separate note, we wanted to also convert PDF file to image, do you have a example code for us to use, please?

We also want to extract text from slides (all ppt format and PDF), could you also send me sample code for this?

Many thanks,
Sheng

Hi Sheng,

Its good to know that things are resolved on your end after installation of fonts. As far as extracting text from presentation is concerned, I request you to please visit this java documentation link for your kind reference. You may please port the java code to appropriate PHP code to serve the purpose on your end.

For PDF to Image and PDF text extraction, I will request Aspose.Pdf support team to share the feedback.

Many Thanks,

juplus:
On a separate note, we wanted to also convert PDF file to image, do you have a example code for us to use, please?
Hi Sheng,

Thanks for using our API’s.

We have an API named Aspose.Pdf for Java which offers the feature to convert PDF pages to Image format. For more information, please visit Convert PDF Pages to JPEG Image

juplus:

We also want to extract text from slides (all ppt format and PDF), could you also send me sample code for this?
Aspose.Pdf for Java also offers the feature to extract text from PDF files. For further details, please visit Search and Get Text

In case you encounter any issue, please share your resource/input documents, so that we can test the scenario in our environment.

Hi Nayyer,


Thanks for your reply.

Could you also send me the link for the sample code of extracting text from PPT file (and any other Power Point file format) please?

Thanks,
Sheng

Hi Sheng,

As shared earlier, please visit this java documentation link to extract the text from presentation. You may port the code to PHP to serve the purpose. I hope this will be helpful.

Many Thanks,