public static function run($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Adding the Media Player ActiveX control $controlType = new ControlType(); $pres->getSlides()->get_Item(0)->getControls()->addControl($controlType->WindowsMediaPlayer, 100, 100, 400, 400); # Access the Media Player ActiveX control and set the video path $pres->getSlides()->get_Item(0)->getControls()->get_Item(0)->getProperties()->set_Item("URL", $dataDir . "Wildlife.mp4"); # Write the presentation as a PPTX file $saveFormat = new SaveFormat(); $pres->save($dataDir . "AddActiveX.pptx", $saveFormat->Pptx); print "Added ActiveX control, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'demo.pptx'); $transition_type = new TransitionType(); # Apply circle type transition on slide 1 $pres->getSlides()->get_Item(0)->getSlideShowTransition()->setType($transition_type->Circle); # Apply comb type transition on slide 2 $pres->getSlides()->get_Item(1)->getSlideShowTransition()->setType($transition_type->Comb); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "SimpleTransition.pptx", $save_format->Pptx); print "Done with simple transition, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation $pres = new Presentation(); # Get the first slide $slide = $pres->getSlides()->get_Item(0); # Add an AutoShape of Rectangle type $shape_type = new ShapeType(); $ashp = $slide->getShapes()->addAutoShape($shape_type->Rectangle, 150, 75, 150, 50); # Add ITextFrame to the Rectangle $ashp->addTextFrame("Hello World"); # Change the text color to Black (which is White by default) $fill_type = new FillType(); $color = new Color(); $ashp->getTextFrame()->getParagraphs()->get_Item(0)->getPortions()->get_Item(0)->getPortionFormat()->getFillFormat()->setFillType($fill_type->Solid); $ashp->getTextFrame()->getParagraphs()->get_Item(0)->getPortions()->get_Item(0)->getPortionFormat()->getFillFormat()->getSolidFillColor()->setColor($color->BLACK); # Change the line color of the rectangle to White $ashp->getShapeStyle()->getLineColor()->setColor($color->WHITE); # Remove any fill formatting in the shape $ashp->getFillFormat()->setFillType($fill_type->NoFill); # Save the presentation to disk $save_format = new SaveFormat(); $pres->save($dataDir . "HelloWorld.pptx", $save_format->Pptx); print "Document has been saved, please check the output file."; }
public static function run($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $slide = $pres->getSlides()->get_Item(0); # Add an AutoShape of Rectangle type $shapeType = new ShapeType(); $shp = $slide->getShapes()->addAutoShape($shapeType->Rectangle, 150, 75, 150, 50); # Add TextFrame to the Rectangle $shp->addTextFrame("Aspose TextBox"); # Disable shape fill in case we want to get shadow of text $fillType = new FillType(); $shp->getFillFormat()->setFillType($fillType->NoFill); # Add outer shadow and set all necessary parameters $shp->getEffectFormat()->enableOuterShadowEffect(); $shadow = $shp->getEffectFormat()->getOuterShadowEffect(); $shadow->setBlurRadius(4.0); $shadow->setDirection(45); $shadow->setDistance(3); $rectangleAlignment = new RectangleAlignment(); $color = new Color(); $shadow->setRectangleAlign($rectangleAlignment->TopLeft); $shadow->getShadowColor()->setColor($color->black); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "OutShadow.pptx", $save_format->Pptx); print "Applied shadow effects on text, please check the output file." . PHP_EOL; }
public static function add_arrow_line($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Add an autoshape of type line $shapeType = new ShapeType(); $shp = $sld->getShapes()->addAutoShape($shapeType->Line, 50, 150, 300, 0); # Apply some formatting on the line $lineStyle = new LineStyle(); $shp->getLineFormat()->setStyle($lineStyle->ThickBetweenThin); $shp->getLineFormat()->setWidth(10); $lineDashStyle = new LineDashStyle(); $shp->getLineFormat()->setDashStyle($lineDashStyle->DashDot); $lineArrowheadLength = new LineArrowheadLength(); $lineArrowheadStyle = new LineArrowheadStyle(); $fillType = new FillType(); $color = new Color(); $presetColor = new PresetColor(); $shp->getLineFormat()->setBeginArrowheadLength($lineArrowheadLength->Short); $shp->getLineFormat()->setBeginArrowheadStyle($lineArrowheadStyle->Oval); $shp->getLineFormat()->setEndArrowheadLength($lineArrowheadLength->Long); $shp->getLineFormat()->setEndArrowheadStyle($lineArrowheadStyle->Triangle); $shp->getLineFormat()->getFillFormat()->setFillType($fillType->Solid); $shp->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor(new Color($presetColor->Maroon)); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "ArrowShape.pptx", $save_format->Pptx); print "Added arrow shape line to slide, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $slide = $pres->getSlides()->get_Item(0); # Add an AutoShape of Rectangle type $shapeType = new ShapeType(); $fillType = new FillType(); $ashp = $slide->getShapes()->addAutoShape($shapeType->Rectangle, 150, 75, 400, 300); $ashp->getFillFormat()->setFillType($fillType->NoFill); # Add TextFrame to the Rectangle $ashp->addTextFrame("Aspose TextBox"); $port = $ashp->getTextFrame()->getParagraphs()->get_Item(0)->getPortions()->get_Item(0); $pf = $port->getPortionFormat(); $pf->setFontHeight(50); # Enable InnerShadowEffect $ef = $pf->getEffectFormat(); $ef->enableInnerShadowEffect(); # Set all necessary parameters $ef->getInnerShadowEffect()->setBlurRadius(8.0); $ef->getInnerShadowEffect()->setDirection(90); $ef->getInnerShadowEffect()->setDistance(6.0); $ef->getInnerShadowEffect()->getShadowColor()->setB(189); # Set ColorType as Scheme $colorType = new ColorType(); $ef->getInnerShadowEffect()->getShadowColor()->setColorType($colorType->Scheme); # Set Scheme Color $schemeColor = new SchemeColor(); $ef->getInnerShadowEffect()->getShadowColor()->setSchemeColor($schemeColor->Accent1); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "WordArt.pptx", $save_format->Pptx); print "Done with word art, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'demo.pptx'); # Getting last slide index $last_slide_position = java_values($pres->getSlides()->size()); #Iterating through every presentation slide and generating SVG image $i = 0; while ($i < $last_slide_position) { # Accessing Slides $slide = $pres->getSlides()->get_Item($i); # Getting and saving the slide SVG image $slide->writeAsSvg(new FileOutputStream($dataDir . "SvgImage#{$i}.svg")); $i++; } print "Created SVG images, please check output files." . PHP_EOL; }
public static function set_size_and_type($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'demo.pptx'); $aux_pres = new Presentation(); $slide = $pres->getSlides()->get_Item(0); # Set the slide size of generated presentations to that of source $aux_pres->getSlideSize()->setType($pres->getSlideSize()->getType()); $aux_pres->getSlideSize()->setSize($pres->getSlideSize()->getSize()); # Clone required slide $aux_pres->getSlides()->addClone($pres->getSlides()->get_Item(0)); $aux_pres->getSlides()->removeAt(0); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "Slide_Size_Type.pptx", $save_format->Pptx); print "Set slide size and type, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation($dataDir . 'demo.pptx'); # Get the first slide $slide = $pres->getSlides()->get_Item(0); $shape = FindShape::find_shape($slide, "Shape1"); print "Shape: " . $shape . PHP_EOL; }
public static function get_slide_by_id($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'Aspose.pptx'); # Getting Slide ID $id = $pres->getSlides()->get_Item(0)->getSlideId(); # Accessing Slide by ID $slide = $pres->getSlideById($id); print "Slide: " . $slide . PHP_EOL; }
public static function run($dataDir = null) { $pres = new Presentation(); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Define columns with widths and rows with heights $dbl_cols = [50, 50, 50]; $dbl_rows = [50, 30, 30, 30]; # Add table shape to slide $tbl = $sld->getShapes()->addTable(100, 50, $dbl_cols, $dbl_rows); $fill_type = new FillType(); $color = new Color(); # Set border format for each cell $row = 0; while ($row < java_values($tbl->getRows()->size())) { $cell = 0; while ($cell < $tbl->getRows()->get_Item($row)->size()) { $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderTop()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderTop()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderTop()->setWidth(5); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderBottom()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderBottom()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderBottom()->setWidth(5); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderLeft()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderLeft()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderLeft()->setWidth(5); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderRight()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderRight()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderRight()->setWidth(5); $cell += 1; } $row += 1; } $tbl->getColumns()->get_Item(0)->get_Item(0)->getTextFrame()->setText("00"); $tbl->getColumns()->get_Item(0)->get_Item(1)->getTextFrame()->setText("01"); $tbl->getColumns()->get_Item(0)->get_Item(2)->getTextFrame()->setText("02"); $tbl->getColumns()->get_Item(0)->get_Item(3)->getTextFrame()->setText("03"); $tbl->getColumns()->get_Item(1)->get_Item(0)->getTextFrame()->setText("10"); $tbl->getColumns()->get_Item(2)->get_Item(0)->getTextFrame()->setText("20"); $tbl->getColumns()->get_Item(1)->get_Item(1)->getTextFrame()->setText("11"); $tbl->getColumns()->get_Item(2)->get_Item(1)->getTextFrame()->setText("21"); # AddClone adds a row in the end of the table $tbl->getRows()->addClone($tbl->getRows()->get_Item(0), false); # AddClone adds a column in the end of the table $tbl->getColumns()->addClone($tbl->getColumns()->get_Item(0), false); # InsertClone adds a row at specific position in a table $tbl->getRows()->insertClone(2, $tbl->getRows()->get_Item(0), false); # InsertClone adds a row at specific position in a table $tbl->getColumns()->insertClone(2, $tbl->getColumns()->get_Item(0), false); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "CloneRowColumn.pptx", $save_format->Pptx); print "Cloned Row & Column from table, please check the output file."; PHP_EOL; }
public static function remove_slide_by_id($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'Aspose.pptx'); # Removing a slide using its slide index $pres->getSlides()->removeAt(1); # Saving the presentation file $save_format = new SaveFormat(); $pres->save($dataDir . "Modified.pptx", $save_format->Pptx); print "Removed slide by ID, please check the output file." . PHP_EOL; }
public static function set_image_as_background_color($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation(); # Set the background with Image $backgroundType = new BackgroundType(); $fillType = new FillType(); $pictureFillMode = new PictureFillMode(); $pres->getSlides()->get_Item(0)->getBackground()->setType($backgroundType->OwnBackground); $pres->getSlides()->get_Item(0)->getBackground()->getFillFormat()->setFillType($fillType->Picture); $pres->getSlides()->get_Item(0)->getBackground()->getFillFormat()->getPictureFillFormat()->setPictureFillMode($pictureFillMode->Stretch); # Set the picture $imgx = $pres->getImages()->addImage(new FileInputStream(new File($dataDir . 'night.jpg'))); # Image imgx = pres.getImages().addImage(image); # Add image to presentation's images collection $pres->getSlides()->get_Item(0)->getBackground()->getFillFormat()->getPictureFillFormat()->getPicture()->setImage($imgx); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "ContentBG_Image.pptx", $save_format->Pptx); print "Set image as background, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'Aspose.pptx'); # Get the slide whose position is to be changed $slide = $pres->getSlides()->get_Item(0); # Set the new position for the slide $slide->setSlideNumber(2); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "Aspose_Position.pptx", $save_format->Pptx); print "Changes slide position, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation($dataDir . 'Welcome.pptx'); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Change the text of each placeholder $shp = $sld->getShapes()->get_Item(0); $shp->getTextFrame()->setText("This is Placeholder"); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "Welcome_PH.pptx", $save_format->Pptx); print "Replaced text, please check the output file." . PHP_EOL; }
public static function create_smartart_shape($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $slide = $pres->getSlides()->get_Item(0); # Add Smart Art Shape $smartArtLayoutType = new SmartArtLayoutType(); $smart = $slide->getShapes()->addSmartArt(0, 0, 400, 400, $smartArtLayoutType->BasicBlockList); # Write the presentation as a PPTX file $saveFormat = new SaveFormat(); $pres->save($dataDir . "SimpleSmartArt.pptx", $saveFormat->Pptx); print "Created smartart shape, please check the output file." . PHP_EOL; }
public static function add_custom_error_bar_value($dataDir = null) { $pres = new Presentation(); $slide = $pres->getSlides()->get_Item(0); # Creating a bubble chart $chartType = new ChartType(); $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart($chartType->Bubble, 50, 50, 400, 300, true); # Adding custom Error bars and setting its format $error_bar_value_type = new ErrorBarValueType(); $series = $chart->getChartData()->getSeries()->get_Item(0); $error_bar_x = $series->getErrorBarsXFormat(); $error_bar_y = $series->getErrorBarsYFormat(); #error_bar_x.isVisible(true) #error_bar_y.isVisible(true) $error_bar_x->setValueType($error_bar_value_type->Custom); $error_bar_y->setValueType($error_bar_value_type->Custom); #Accessing chart series data point and setting error bars values for individual point $data_source_type = new DataSourceType(); $points = $series->getDataPoints(); $points->getDataSourceTypeForErrorBarsCustomValues()->setDataSourceTypeForXPlusValues($data_source_type->DoubleLiterals); $points->getDataSourceTypeForErrorBarsCustomValues()->setDataSourceTypeForXMinusValues($data_source_type->DoubleLiterals); $points->getDataSourceTypeForErrorBarsCustomValues()->setDataSourceTypeForYPlusValues($data_source_type->DoubleLiterals); $points->getDataSourceTypeForErrorBarsCustomValues()->setDataSourceTypeForYMinusValues($data_source_type->DoubleLiterals); # Setting error bars for chart series points $i = 0; while ($i < $points->size()) { $points->get_Item($i)->getErrorBarsCustomValues()->getXMinus()->setAsLiteralDouble($i + 1); $points->get_Item($i)->getErrorBarsCustomValues()->getXPlus()->setAsLiteralDouble($i + 1); $points->get_Item($i)->getErrorBarsCustomValues()->getYMinus()->setAsLiteralDouble($i + 1); $points->get_Item($i)->getErrorBarsCustomValues()->getYPlus()->setAsLiteralDouble($i + 1); $i++; } $save_format = new SaveFormat(); $pres->save($dataDir . "ErrorBarsCustomValues.pptx", $save_format->Pptx); print "Added custom error bars values for chart, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { $pres = new Presentation(); # Get the first slide $slide = $pres->getSlides()->get_Item(0); $col_width = [100, 50, 30]; $row_height = [30, 50, 30]; $table = $slide->getShapes()->addTable(100, 100, $col_width, $row_height); $table->getRows()->removeAt(1, false); $table->getColumns()->removeAt(1, false); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "RemoveRowColumn.pptx", $save_format->Pptx); print "Removed Row & Column from table, please check the output file." . PHP_EOL; }
public static function create_thumbnail_of_user_defined_window($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . 'demo.pptx'); # Access the first slide $slide = $pres->getSlides()->get_Item(0); # Create a full scale image $image = $slide->getThumbnail(1, 1); # Getting the image of desired window inside generated slide thumnbnail # BufferedImage window = image.getSubimage(windowX, windowY, windowsWidth, windowHeight); $window_image = $image->getSubimage(100, 100, 200, 200); # Save the image to disk in JPEG format $imageIO = new ImageIO(); $imageIO->write($image, "jpeg", new File($dataDir . "ContentBG_tnail.jpg")); print "Created thumbnail of user defined window, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Add autoshape of rectangle type $shapeType = new ShapeType(); $shp = $sld->getShapes()->addAutoShape($shapeType->Rectangle, 50, 150, 75, 150); # Rotate the shape to 90 degree $shp->setRotation(90); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "RectShpRot.pptx", $save_format->Pptx); print "Rotated shape, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation(); # Access first slide $sld = $pres->getSlides()->get_Item(0); # Adding a chart on slide $chartType = new ChartType(); $ch = $sld->getShapes()->addChart($chartType->ClusteredColumn, 20, 20, 500, 300); # Setting the position of label from axis $ch->getAxes()->getHorizontalAxis()->setLabelOffset(500); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "Position.pptx", $save_format->Pptx); print "Set label distance, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation($dataDir . "AsposeChart.pptx"); # Access first slide $sld = $pres->getSlides()->get_Item(0); # Add chart with default data $chart = $sld->getShapes()->get_Item(0); # Setting the index of chart data sheet $defaultWorksheetIndex = 0; # Getting the chart data worksheet $fact = $chart->getChartData()->getChartDataWorkbook(); # Changing chart Category Name $fact->getCell($defaultWorksheetIndex, 1, 0, "Modified Category 1"); $fact->getCell($defaultWorksheetIndex, 2, 0, "Modified Category 2"); # Take first chart series $series = $chart->getChartData()->getSeries()->get_Item(0); # Now updating series data $fact->getCell($defaultWorksheetIndex, 0, 1, "New_Series1"); # modifying series name $series->getDataPoints()->get_Item(0)->getValue()->setData(90); $series->getDataPoints()->get_Item(1)->getValue()->setData(123); $series->getDataPoints()->get_Item(2)->getValue()->setData(44); # Take Second chart series $series = $chart->getChartData()->getSeries()->get_Item(1); # Now updating series data $fact->getCell($defaultWorksheetIndex, 0, 2, "New_Series2"); #modifying series name $series->getDataPoints()->get_Item(0)->getValue()->setData(23); $series->getDataPoints()->get_Item(1)->getValue()->setData(67); $series->getDataPoints()->get_Item(2)->getValue()->setData(99); # Now, Adding a new series $chart->getChartData()->getSeries()->add($fact->getCell($defaultWorksheetIndex, 0, 3, "Series 3"), $chart->getType()); # Take 3rd chart series $series = $chart->getChartData()->getSeries()->get_Item(2); # Now populating series data $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, 1, 3, 20)); $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, 2, 3, 50)); $series->getDataPoints()->addDataPointForBarSeries($fact->getCell($defaultWorksheetIndex, 3, 3, 30)); $chartType = new ChartType(); $chart->setType($chartType->ClusteredCylinder); # Saving the presentation to HTML format $save_format = new SaveFormat(); $pres->save($dataDir . "AsposeChartModified.pptx", $save_format->Pptx); print "Updated chart, please check the output file." . PHP_EOL; }
public static function add_overlap_for_chart($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation(); # Adding chart $chartType = new ChartType(); $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart($chartType->ClusteredColumn, 50, 50, 600, 400, true); $series = $chart->getChartData()->getSeries(); if ($series->get_Item(0)->getOverlap() == 0) { # Setting series overlap $series->get_Item(0)->getParentSeriesGroup()->setOverlap(-30); } # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "Overlap.pptx", $save_format->Pptx); print "Added chart series overlap for charts, please check the output file." . PHP_EOL; }
public static function format_join_styles($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Add three autoshapes of rectangle type $shape_type = new ShapeType(); $shp1 = $sld->getShapes()->addAutoShape($shape_type->Rectangle, 50, 100, 150, 75); $shp2 = $sld->getShapes()->addAutoShape($shape_type->Rectangle, 300, 100, 150, 75); $shp3 = $sld->getShapes()->addAutoShape($shape_type->Rectangle, 50, 250, 150, 75); # Set the fill color of the rectangle shape $fill_type = new FillType(); $color = new Color(); $shp1->getFillFormat()->setFillType($fill_type->Solid); $shp1->getFillFormat()->getSolidFillColor()->setColor($color->BLACK); $shp2->getFillFormat()->setFillType($fill_type->Solid); $shp2->getFillFormat()->getSolidFillColor()->setColor($color->BLACK); $shp3->getFillFormat()->setFillType($fill_type->Solid); $shp3->getFillFormat()->getSolidFillColor()->setColor($color->BLACK); # Set the line width $shp1->getLineFormat()->setWidth(15); $shp2->getLineFormat()->setWidth(15); $shp3->getLineFormat()->setWidth(15); # Set the color of the line of rectangle $shp1->getLineFormat()->getFillFormat()->setFillType($fill_type->Solid); $shp1->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor($color->BLUE); $shp2->getLineFormat()->getFillFormat()->setFillType($fill_type->Solid); $shp2->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor($color->BLUE); $shp3->getLineFormat()->getFillFormat()->setFillType($fill_type->Solid); $shp3->getLineFormat()->getFillFormat()->getSolidFillColor()->setColor($color->BLUE); # Set the Join Style $line_join_style = new LineJoinStyle(); $shp1->getLineFormat()->setJoinStyle($line_join_style->Miter); $shp2->getLineFormat()->setJoinStyle($line_join_style->Bevel); $shp3->getLineFormat()->setJoinStyle($line_join_style->Round); # Add text to each rectangle $shp1->getTextFrame()->setText("This is Miter Join Style"); $shp2->getTextFrame()->setText("This is Bevel Join Style"); $shp3->getTextFrame()->setText("This is Round Join Style"); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "RectShpLnJoin.pptx", $save_format->Pptx); print "Formatted join styles, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Instantiate Presentation class that represents the presentation file $pres = new Presentation(); # Instantiate SlideCollection calss $slides = $pres->getSlides(); $i = 0; while ($i < $pres->getLayoutSlides()->size()) { # Add an empty slide to the Slides collection $slides->addEmptySlide($pres->getLayoutSlides()->get_Item($i)); $i += 1; } #Do some work on the newly added slide # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "EmptySlide.pptx", $save_format->Pptx); print "Document has been created, please check the output file."; }
public static function add_video_frame($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $sId = $pres->getSlides()->get_Item(0); # Add Video Frame $vf = $sId->getShapes()->addVideoFrame(50, 150, 300, 150, $dataDir . "Wildlife.mp4"); # Set Play Mode and Volume of the Video $videoPlayModePreset = new VideoPlayModePreset(); $audioVolumeMode = new AudioVolumeMode(); $vf->setPlayMode($videoPlayModePreset->Auto); $vf->setVolume($audioVolumeMode->Loud); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "VideoFrame.pptx", $save_format->Pptx); print "Added video frame to slide, please check the output file." . PHP_EOL; }
public static function set_location_and_size($dataDir = null) { # Creating empty presentation $pres = new Presentation(); # Get reference of the slide $slide = $pres->getSlides()->get_Item(0); # Add a clustered column chart on the slide $chartType = new ChartType(); $chart = $slide->getShapes()->addChart($chartType->ClusteredColumn, 50, 50, 500, 500); # Set Legend Properties $chart->getLegend()->setX(50 / $chart->getWidth()); $chart->getLegend()->setY(50 / $chart->getHeight()); $chart->getLegend()->setWidth(100 / $chart->getWidth()); $chart->getLegend()->setHeight(100 / $chart->getHeight()); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "Legend.pptx", $save_format->Pptx); print "Set custom location and size of chart legend, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { # Creating empty presentation $pres = new Presentation(); # Creating a clustered column chart $chartType = new ChartType(); $chart = $pres->getSlides()->get_Item(0)->getShapes()->addChart($chartType->ClusteredColumn, 20, 20, 500, 400); # Adding ponential trend line for chart series 1 $trendlineType = new TrendlineType(); $tredLinep = $chart->getChartData()->getSeries()->get_Item(0)->getTrendLines()->add($trendlineType->Exponential); $tredLinep->setDisplayEquation(false); $tredLinep->setDisplayRSquaredValue(false); # Adding Linear trend line for chart series 1 $fillType = new FillType(); $color = new Color(); $tredLineLin = $chart->getChartData()->getSeries()->get_Item(0)->getTrendLines()->add($trendlineType->Linear); $tredLineLin->setTrendlineType($trendlineType->Linear); $tredLineLin->getFormat()->getLine()->getFillFormat()->setFillType($fillType->Solid); $tredLineLin->getFormat()->getLine()->getFillFormat()->getSolidFillColor()->setColor($color->RED); # Adding Logarithmic trend line for chart series 2 $tredLineLog = $chart->getChartData()->getSeries()->get_Item(1)->getTrendLines()->add($trendlineType->Logarithmic); $tredLineLog->setTrendlineType($trendlineType->Logarithmic); $tredLineLog->addTextFrameForOverriding("New log trend line"); # Adding MovingAverage trend line for chart series 2 $tredLineMovAvg = $chart->getChartData()->getSeries()->get_Item(1)->getTrendLines()->add($trendlineType->MovingAverage); $tredLineMovAvg->setTrendlineType($trendlineType->MovingAverage); $tredLineMovAvg->setPeriod(3); $tredLineMovAvg->setTrendlineName("New TrendLine Name"); # Adding Polynomial trend line for chart series 3 $tredLinePol = $chart->getChartData()->getSeries()->get_Item(2)->getTrendLines()->add($trendlineType->Polynomial); $tredLinePol->setTrendlineType($trendlineType->Polynomial); $tredLinePol->setForward(1); $tredLinePol->setOrder(3); # Adding Power trend line for chart series 3 $tredLinePower = $chart->getChartData()->getSeries()->get_Item(1)->getTrendLines()->add($trendlineType->Power); $tredLinePower->setTrendlineType($trendlineType->Power); $tredLinePower->setBackward(1); # Saving the presentation $save_format = new SaveFormat(); $pres->save($dataDir . "ChartTrendLines.pptx", $save_format->Pptx); print "Done with chart trend lines, please check the output file." . PHP_EOL; }
public static function run($dataDir = null) { $pres = new Presentation(); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Define columns with widths and rows with heights $dblCols = [50, 50, 50]; $dblRows = [50, 30, 30, 30, 30]; # Add table shape to slide $tbl = $sld->getShapes()->addTable(100, 50, $dblCols, $dblRows); $fill_type = new FillType(); $color = new Color(); # Set border format for each cell $row = 0; while ($row < java_values($tbl->getRows()->size())) { $cell = 0; while ($cell < $tbl->getRows()->get_Item($row)->size()) { $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderTop()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderTop()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderTop()->setWidth(5); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderBottom()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderBottom()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderBottom()->setWidth(5); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderLeft()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderLeft()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderLeft()->setWidth(5); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderRight()->getFillFormat()->setFillType($fill_type->Solid); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderRight()->getFillFormat()->getSolidFillColor()->setColor($color->RED); $tbl->getRows()->get_Item($row)->get_Item($cell)->getBorderRight()->setWidth(5); $cell++; } $row++; } # Merge cells 1 & 2 of row 1 $tbl->mergeCells($tbl->getRows()->get_Item(0)->get_Item(0), $tbl->getRows()->get_Item(1)->get_Item(0), false); # Add text to the merged cell $tbl->getRows()->get_Item(0)->get_Item(0)->getTextFrame()->setText("Merged Cells"); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "CreateTable.pptx", $save_format->Pptx); print "Created table, please check the output file." . PHP_EOL; }
public static function fill_shapes_with_solid_color($dataDir = null) { # Create an instance of Presentation class $pres = new Presentation(); # Get the first slide $sld = $pres->getSlides()->get_Item(0); # Add autoshape of rectangle type $shapeType = new ShapeType(); $shp = $sld->getShapes()->addAutoShape($shapeType->Rectangle, 50, 150, 75, 150); # Set the fill type to Solid $fillType = new FillType(); $shp->getFillFormat()->setFillType($fillType->Solid); # Set the color of the rectangle $color = new Color(); $shp->getFillFormat()->getSolidFillColor()->setColor($color->YELLOW); # Write the presentation as a PPTX file $save_format = new SaveFormat(); $pres->save($dataDir . "RectShpSolid.pptx", $save_format->Pptx); print "Filled shapes with Solid Color, please check the output file."; }