Create a PowerPoint2007 document using PHP
This morning from the subscription of Zend Devzone see a very interesting article. Creating PowerPoint files using PHP. Tried it. I really mean it and share it with everyone.
The program requires PHP 5.2 or more environments, plus the php_zip and php_xml extension modules are supported. In addition, you need to download the Phppowerpoint class library. Official website address: http://phppowerpoint.codeplex.com/The current stable version is 0.1.0
It has been downloaded here. You can download this site directly with the sample code. I have a good bag. Click here to download the sample package. Another official send original package with API documentation also has official sample program also put out official package download.
Tell me how it feels. This class library is also available. Coding is very canonical. A completely PHP5 style. I like the type. Same as the Zend Framework. Processing speed is also very fast. This time it was only a simple test. More advanced features don't take the time to play. Post the test code, please.
-
- /**
- * PHP generates a PowerPoint 2007 sample script.
- *
- * This program requires PHP 5.2 or higher, requires php_zip and php_xml extension support.
- * Usually win under the program as long as the php_zip extension can be opened, Php_xml extension built-in support.
- * Linux needs to be adjusted according to the compilation conditions.
- *
- * @author: Guya
- * @since: 2009-4-30
- */
- //directory split symbol
- Define (' DS ', directory_separator);
- //define root directory
- Define (' ROOT ', dirname (__file__). DS);
- //Modify the Include path, and the Phppowerpoint package is placed in the Libs directory of the current directory.
- Set_include_path (Get_include_path (). Path_separator. ROOT. ' Libs ' );
- //Do not limit script run time limits.
- Set_time_limit (0);
- //Simple setup Auto load function.
- function __autoload ($className) {
- ???? include_once (str_replace("_", DS, $className). ". php" );??
- }
- //Create a new Phppowerpoint object.
- $PPP = New phppowerpoint ();
- //Get one page of slides currently in use
- $activeSlide = $PPP ->getactiveslide ();
- //Add a picture to the slideshow.
- $shape = $activeSlide ->createdrawingshape ();
- //Set picture name.
- $shape ->setname (' mmclub.net Logo ');
- //Set descriptive information for the picture.
- $shape ->setdescription (' mmclub.net Logo ');
- //Picture actual path
- $shape ->setpath (ROOT. ' mmclub.net.jpg ' );
- //Picture height
- $shape ->setheight (103);
- //Set Picture width
- $shape ->setwidth (339);
- //Set the picture relative to the upper-left corner x position, per pixel
- $shape ->setoffsetx (ten);
- //Set the picture relative to the upper-left corner y position, per pixel
- $shape ->setoffsety (ten);
- //Set diagram display status
- $shape ->getshadow ()->setvisible (true);
- $shape ->getshadow ()->setdirection ();
- $shape ->getshadow ()->setdistance ();
- //Set a text box
- $shape = $activeSlide ->createrichtextshape ();
- //Set text box height, per pixel
- $shape ->setheight ();
- //Set text box width, per pixel
- $shape ->setwidth (+);
- //Set the text box relative to the upper-left corner x position, per pixel
- $shape ->setoffsetx ();
- //Set the text box relative to the upper-left corner y position, per pixel
- $shape ->setoffsety ($);
- //sets the text layout position to be horizontally centered and centered vertically.
- $shape ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_center);
- $shape ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
- //Set text box text content. Test No Chinese in the Chinese environment. If you are in e-context. Note that you want to specify fonts that support Chinese. Otherwise it might be garbled.
- $textRun = $shape ->createtextrun (' Welcome to use PHPPowerPoint2007 ');
- //Use font bold
- $textRun ->getfont ()->setbold (true);
- //Set the font size to 38, and note the text size setting here. The size of the preceding text box is fixed. If the text exceeds the container will be discharged to the bottom of the container
- $textRun ->getfont ()->setsize ();
- //Set text color, here is ARGB mode, 16 binary mode, front 2 bit is transparency, followed by RGB value. Set to Blue Blue
- $textRun ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' FFFF0000 ' )) ;
- //Set a few more text boxes below
- $shape 0 = $activeSlide ->createrichtextshape ();
- $shape 0 ->setheight (+);
- $shape 0 ->setwidth (+);
- $shape 0 ->setoffsetx (+);
- $shape 0 ->setoffsety (+);
- $shape 0 ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_center);
- $shape 0 ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
- $textRun 0 = $shape 0 ->createtextrun (' http://www.mmclub.net ');
- $textRun 0 ->getfont ()->setsize ( +);
- $textRun 0 ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' ff0000ff ' ));
- $shape 1 = $activeSlide ->createrichtextshape ();
- $shape 1 ->setheight (+);
- $shape 1 ->setwidth ($);
- $shape 1 ->setoffsetx (a);
- $shape 1 ->setoffsety (+);
- $shape 1 ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
- $shape 1 ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
- $textRun 1 = $shape 1 ->createtextrun (' Author:guya ');
- $textRun 1 ->getfont ()->setsize ();
- $textRun 1 ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' FF000000 ') ) );
- $shape 2 = $activeSlide ->createrichtextshape ();
- $shape 2 ->setheight (+);
- $shape 2 ->setwidth ($);
- $shape 2 ->setoffsetx (a);
- $shape 2 ->setoffsety (540);
- $shape 2 ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
- $shape 2 ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
- $textRun 2 = $shape 2 ->createtextrun (' date:2009-4-30 ');
- $textRun 2 ->getfont ()->setsize ();
- $textRun 2 ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' FF000000 ') ) );
- //Save pptx file, use 2007 format
- $objWriter = Phppowerpoint_iofactory::createwriter ($ppp, ' PowerPoint2007 ') ;
- //Save file
- $objWriter ->save (ROOT. ' Myphpppt.pptx ' );
- Echo ' ppt create success! ' ;
- ?>
The application of this thing to the future. It's still useful in some places on the web. The friends you need can spend a little more time studying.
This article source: http://blog.mmclub.net/index/view/article_id/89
There are very few related materials on the Internet, looking for a long time, take up to share with you, and thank the author.