How can i add multiple images using php powerpoint library? -


can u pls tell me how bind multiple images in powerpoint using php powerpoint library? in below code used foreach loop add multiple images in powerpoint 1 image adding pls me.

<?php  require_once("db_config.php"); set_include_path(get_include_path() . path_separator . 'classes/'); include 'phppowerpoint.php'; include 'phppowerpoint/iofactory.php'; ?> <html> <h3 align="center">welcome <?php echo $_session['user_name'];?>   <br> <a href="logout.php">logout</a> </h3> <body> <?php  echo "<div align='center'>"; echo "<form method='post' action=''>"; echo "<table align='center' border='1'> <tr> <th></th> <th>id</th> <th>firstname</th> <th>lastname</th> <th>username</th> </tr>"; $result = mysql_query("select * users"); while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td><input type='checkbox' name='user_id[]' value='".$row['user_id']."' />  </td>"; echo "<td>" . $row['user_id'] . "</td>"; echo "<td>" . $row['first_name'] . "</td>"; echo "<td>" . $row['last_name'] . "</td>"; echo "<td>" . $row['user_name'] . "</td>"; echo "</tr>";  } echo "</table><br>"; echo "<input type='submit' name='submit' value='export ppt' />"; echo "</form></div>"; ?> </body> </html> <?php if(isset($_post['submit']) && isset($_post['user_id'])){ $user_id = $_post['user_id'];  foreach($user_id $selected){ echo $selected."</br>";  $result = mysql_query("select * users user_id ='".$selected."'"); $row = mysql_fetch_array($result);  $img = '<img src="images/'.$row["image_name"].'" height="200" width="300"    />';  $objphppowerpoint = new phppowerpoint(); // block sets slide logo. $currentslide = $objphppowerpoint->getactiveslide(); $shape = $currentslide->createdrawingshape(); $shape->setpath('images/'.$row["image_name"]); $shape->setwidth(640);  $shape->setheight(480); $shape->setoffsetx(10); $shape->setoffsety(10);  // block sets text first slide. $shape = $currentslide->createrichtextshape(); $shape->setheight(700); $shape->setwidth(600); $shape->setoffsetx(10); $shape->setoffsety(500); $shape->getalignment()->sethorizontal(        phppowerpoint_style_alignment::horizontal_center ); $textrun = $shape->createtextrun('firstname:'.$row["first_name"].'   lastname:'.$row["last_name"].' username:'.$row["user_name"]); $textrun->getfont()->setbold(true); $textrun->getfont()->setsize(30); $textrun->getfont()->setcolor( new phppowerpoint_style_color( '#ffff' ) );  // block sets text first slide ends.  $filename = str_replace('.php', '.pptx', __file__); $newname = "presentationreport-" . date('y-m-d-h-i-s') . ".pptx"; $objwriter = phppowerpoint_iofactory::createwriter($objphppowerpoint, 'powerpoint2007'); $objwriter->save(str_replace('.php', '.pptx', __file__));  // block download file. header("pragma: no-cache"); header("expires: 0"); header("cache-control: must-revalidate, post-check=0, pre-check=0");  header("content-type: application/force-download"); header("content-type: application/octet-stream"); header("content-type: application/download"); header("content-disposition: attachment;filename=" . $newname); ob_clean(); flush(); readfile($filename); exit(); } } else {  echo "<div align='center'>please choose user</div>"; exit; } ?> 

how can add multiple images using php powerpoint library?

two troubles can indentified in snippet:

1 - you're calling "new powerpoint" each element in foreach, , due override previous slide.

2 - you're positioning shapes in same x/y offset:

$shape->setoffsetx(10); $shape->setoffsety(10); 

so in foreach shapes stacked. functional solution you'll need mount valid algorithm like:

i'll have 4 photos slide example so:

$resultsfromdatabase = $resultsfromdatabase;  // array chunk create "logic" 4 photos ... jump new slide $resultsbyslide = array_chunk($resultsfromdatabase, 4);  // each photo needs independent x offset // note fake values, need calculate them $positionsbyindex = [     0 => 10,     1 => 20,     2 => 30,     3 => 40 ];  foreach ($resultsbyslide $i => $rows) {     // 4 photos -> jump slide , create 1     $ppt->createslide();      // slidecount -1 gets current index     $slideindex = $ppt->getslidecount()-1;     $currentslide = $objphppowerpoint->getactiveslide();       foreach ($rows $position => $row) {         $shape = $currentslide->createdrawingshape();         $shape->setpath('images/'.$row["image_name"]);         $shape->setwidth(640);          $shape->setheight(480);         $shape->setoffsetx($positionsbyindex[$position]); // here point         $shape->setoffsety(10);     } }  

and last point not less important: don't use mysql_* in project use: pdo or mysqli_* instead


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -