Required java libraries

hi there, i’m trying to install the required java components for aspose.slides java version.

- Java runtime 1.4 or above,
- JAI (Java Advanced Imaging API)
Oracle Java Technologies | Oracle
- JAI Image I/O
Oracle Java Technologies | Oracle

i don’t think they’re installed correctly, as i’m getting this error message:

ReferenceClass failed: new javax.media.jai.JAI. Cause: java.lang.ClassNotFoundException: Could not find javax.media.jai.JAI in java_require() path

could you tell me what zip exactly to download, and where to put these files…?

thanks,
luke




This message was posted using Page2Forum from Adding Picture Frame to Slide - Aspose.Slides for .NET and Java

OK I’ve added a bunch of requireds:

java_require(“aspose.slides.jar”);
java_require(“jai_core.jar”);
java_require(“jai_codec.jar”);
java_require(“mlibwrapper_jai.jar”);
java_require(“clibwrapper_jiio.jar”);
java_require(“jai_imageio.jar”);

Which solves the missing jar issue, but now I get this error when I run this line:

$img = $JAI->create(“fileload”,$absolute_path.“images/00000005.jpg”);

ERROR
com.sun.media.jai.codec.SeekableStream

Please help. I’m just trying to insert a JPG into a slide with the PHP/JAVA version. Should be simple right…?

OK I’ve removed the three jars (jai_core,jar, jair_codec, mlibwrapper_jai.jar) into the common/lib folder in Tomcat and this removes any errors.

But when I open the presentation, there’s no image included. Any reasoning for this?

Hello,

It looks like your PHP environment couldn’t find JAI libraries. For PHP, it’s better to put all jar files to %JRE%\lib\ext</b> folder. There should be 5 JAI jars, Aspose.Slides and optionally Aspose.Metafiles:

aspose.metafiles.jar
aspose.slides.jar
clibwrapper_jiio.jar
jai_codec.jar
jai_core.jar
jai_imageio.jar
mlibwrapper_jai.jar

What code you use to add images to a slide? Did you read our Programmer’s Guide? It contains PHP examples.

Yeah, I’m using your picture frame tutorial with the following code:

//Creating a temporary stream to hold the image file
$fistream2=new Java(“java.io.FileInputStream”,$absolute_path.“images/00000005.jpg”);

//Converting the image stream to a simple input stream
$iStream=new Java(“java.io.BufferedInputStream”,$fistream2);

//Creating a picture object
$pic = new Java(“com.aspose.slides.Picture”,$pres,$iStream);

//Adding the picture object to pictures collection of the presentation
//After the picture object is added, the picture is given a uniqe picture Id
$picId = $pres->getPictures()->add($pic);

//Creating JAI class of Java Advanced Imaging API
$JAI=new JavaClass(“javax.media.jai.JAI”);

//Using the Java Advanced Imaging Component
$img = $JAI->create(“fileload”,$absolute_path.“images/00000005.jpg”);

//Calculating picture width and height
$pictureWidth = $img->getWidth() * 4;
$pictureHeight = $img->getHeight() * 4;
echo $img->getWidth();

//Calculating slide width and height
$slideWidth = $slide->getBackground()->getWidth();
$slideHeight = $slide->getBackground()->getHeight();

//Calculating the width and height of picture frame
$pictureFrameWidth = ($slideWidth/2 - $pictureWidth/2);
$pictureFrameHeight = ($slideHeight/2 - $pictureHeight/2);

//Adding picture frame to the slide
$slide->getShapes()->addPictureFrame($picId, $pictureFrameWidth, $pictureFrameHeight, $pictureWidth, $pictureHeight);


It’s tracing out the correct width of the image, but just not showing up. Any help appreciated…

Code looks correct so there shouldn’t be any problems. You can try to experiment with Java at first and after that move code to PHP. May be something wrong with ppt file writing? Could you post whole code please.

Sure. Here you go. Basically if we can get this working my company will move ahead with purchasing a version of Slides…



require_once(“java/Java.inc”);

//require_once(“AsposeSlides.php”);

if (DIRECTORY_SEPARATOR==’/’)
$absolute_path = dirname(FILE).’/’;
else
$absolute_path = str_replace(’\’, ‘/’, dirname(FILE)).’/’;

//Using aspose.slides.jar file so that the classes inside the jar file
//can be used
java_require(“aspose.slides.jar”);
//java_require(“jai_core.jar”);
//java_require(“jai_codec.jar”);
//java_require(“mlibwrapper_jai.jar”);

//java_require(“clibwrapper_jiio.jar”);
// java_require(“jai_imageio.jar”);

//Creating a file input stream to read the PPT file
$fistream=new Java(“java.io.FileInputStream”, $absolute_path.“mycampaign.ppt”);

//Instantiate a Presentation object that represents a PPT file
$pres=new Java(“com.aspose.slides.Presentation”,$fistream);

//Accessing a slide using its slide position
$slide=$pres->getSlideByPosition(1);

//Creating a temporary stream to hold the image file
$fistream2=new Java(“java.io.FileInputStream”,$absolute_path.“images/00000005.jpg”);

//Converting the image stream to a simple input stream
$iStream=new Java(“java.io.BufferedInputStream”,$fistream2);

//Creating a picture object
$pic = new Java(“com.aspose.slides.Picture”,$pres,$iStream);

//Adding the picture object to pictures collection of the presentation
//After the picture object is added, the picture is given a uniqe picture Id
$picId = $pres->getPictures()->add($pic);

//Creating JAI class of Java Advanced Imaging API
$JAI=new JavaClass(“javax.media.jai.JAI”);

//Using the Java Advanced Imaging Component
$img = $JAI->create(“fileload”,$absolute_path.“images/00000005.jpg”);

//Calculating picture width and height
$pictureWidth = $img->getWidth() * 4;
$pictureHeight = $img->getHeight() * 4;
echo $img->getWidth();

//Calculating slide width and height
$slideWidth = $slide->getBackground()->getWidth();
$slideHeight = $slide->getBackground()->getHeight();

//Calculating the width and height of picture frame
$pictureFrameWidth = ($slideWidth/2 - $pictureWidth/2);
$pictureFrameHeight = ($slideHeight/2 - $pictureHeight/2);
echo $pictureFrameWidth;

//Adding picture frame to the slide
$slide->getShapes()->addPictureFrame($picId, $pictureFrameWidth, $pictureFrameHeight, $pictureWidth, $pictureHeight);

// replace id
$myshape=$slide->findShape(“PanelID”);
$myshape->getTextFrame()->getParagraphs()->get(0)->getPortions()->get(0)->setText(“987654”);

// replace title
$myshape=$slide->findShape(“PanelTitle”);
$myshape->getTextFrame()->getParagraphs()->get(0)->getPortions()->get(0)->setText(“Parnell Rise | Parnell | Auckland”);

// replace desc
$myshape=$slide->findShape(“PanelDesc”);
$myshape->getTextFrame()->getParagraphs()->get(0)->getPortions()->get(0)->setText(“Lorem ipsum.”);

// replace stats
$myshape=$slide->findShape(“PanelStats”);
$myshape->getTextFrame()->getParagraphs()->get(0)->getPortions()->get(0)->setText(“PanelType”);
$myshape->getTextFrame()->getParagraphs()->get(1)->getPortions()->get(0)->setText(“PanelTraffic”);
$myshape->getTextFrame()->getParagraphs()->get(2)->getPortions()->get(0)->setText(“Illuminated”);
$myshape->getTextFrame()->getParagraphs()->get(3)->getPortions()->get(0)->setText(“Dimensions”);
$myshape->getTextFrame()->getParagraphs()->get(4)->getPortions()->get(0)->setText(“Direction”);


//Creating a file output stream to write the output file
$fostream=new Java(“java.io.FileOutputStream”,$absolute_path.“modified.ppt”);

//Writing the presentation as a PPT file
$pres->write($fostream);

echo “Presentation Created Successfully.”;

$fistream->close();
$fistream2->close();
$iStream->close();
$fostream->close();

Ok found the problem:

$pictureWidth = $img->getWidth() * 4;

Always returns 4 even though

$img->getWidth()

by itself returns the correct number, 300

I’ve experienced this with other functions, they don’t seem to return standard PHP number variables…?

getWidth() should return standard int value. Try to use java_values() function to unwrap it to PHP type.

$pictureWidth = java_values($img->getWidth()) * 4;