Applying PHP to create PowerPoint2007 documents

Source: Internet
Author: User
Tags zend framework
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.

 
 
  1. /**
  2. * PHP generates a PowerPoint 2007 sample script.
  3. *
  4. * This program requires PHP 5.2 or higher, requires php_zip and php_xml extension support.
  5. * Usually win under the program as long as the php_zip extension can be opened, Php_xml extension built-in support.
  6. * Linux needs to be adjusted according to the compilation conditions.
  7. *
  8. * @author: Guya
  9. * @since: 2009-4-30
  10. */
  11. //directory split symbol
  12. Define (' DS ', directory_separator);
  13. //define root directory
  14. Define (' ROOT ', dirname (__file__). DS);
  15. //Modify the Include path, and the Phppowerpoint package is placed in the Libs directory of the current directory.
  16. Set_include_path (Get_include_path (). Path_separator. ROOT. ' Libs ' );
  17. //Do not limit script run time limits.
  18. Set_time_limit (0);
  19. //Simple setup Auto load function.
  20. function __autoload ($className) {
  21. ???? include_once (str_replace("_", DS, $className). ". php" );??
  22. }
  23. //Create a new Phppowerpoint object.
  24. $PPP = New phppowerpoint ();
  25. //Get one page of slides currently in use
  26. $activeSlide = $PPP ->getactiveslide ();
  27. //Add a picture to the slideshow.
  28. $shape = $activeSlide ->createdrawingshape ();
  29. //Set picture name.
  30. $shape ->setname (' mmclub.net Logo ');
  31. //Set descriptive information for the picture.
  32. $shape ->setdescription (' mmclub.net Logo ');
  33. //Picture actual path
  34. $shape ->setpath (ROOT. ' mmclub.net.jpg ' );
  35. //Picture height
  36. $shape ->setheight (103);
  37. //Set Picture width
  38. $shape ->setwidth (339);
  39. //Set the picture relative to the upper-left corner x position, per pixel
  40. $shape ->setoffsetx (ten);
  41. //Set the picture relative to the upper-left corner y position, per pixel
  42. $shape ->setoffsety (ten);
  43. //Set diagram display status
  44. $shape ->getshadow ()->setvisible (true);
  45. $shape ->getshadow ()->setdirection ();
  46. $shape ->getshadow ()->setdistance ();
  47. //Set a text box
  48. $shape = $activeSlide ->createrichtextshape ();
  49. //Set text box height, per pixel
  50. $shape ->setheight ();
  51. //Set text box width, per pixel
  52. $shape ->setwidth (+);
  53. //Set the text box relative to the upper-left corner x position, per pixel
  54. $shape ->setoffsetx ();
  55. //Set the text box relative to the upper-left corner y position, per pixel
  56. $shape ->setoffsety ($);
  57. //sets the text layout position to be horizontally centered and centered vertically.
  58. $shape ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_center);
  59. $shape ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
  60. //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.
  61. $textRun = $shape ->createtextrun (' Welcome to use PHPPowerPoint2007 ');
  62. //Use font bold
  63. $textRun ->getfont ()->setbold (true);
  64. //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
  65. $textRun ->getfont ()->setsize ();
  66. //Set text color, here is ARGB mode, 16 binary mode, front 2 bit is transparency, followed by RGB value. Set to Blue Blue
  67. $textRun ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' FFFF0000 ' )) ;
  68. //Set a few more text boxes below
  69. $shape 0 = $activeSlide ->createrichtextshape ();
  70. $shape 0 ->setheight (+);
  71. $shape 0 ->setwidth (+);
  72. $shape 0 ->setoffsetx (+);
  73. $shape 0 ->setoffsety (+);
  74. $shape 0 ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_center);
  75. $shape 0 ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
  76. $textRun 0 = $shape 0 ->createtextrun (' http://www.mmclub.net ');
  77. $textRun 0 ->getfont ()->setsize ( +);
  78. $textRun 0 ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' ff0000ff ' ));
  79. $shape 1 = $activeSlide ->createrichtextshape ();
  80. $shape 1 ->setheight (+);
  81. $shape 1 ->setwidth ($);
  82. $shape 1 ->setoffsetx (a);
  83. $shape 1 ->setoffsety (+);
  84. $shape 1 ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
  85. $shape 1 ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
  86. $textRun 1 = $shape 1 ->createtextrun (' Author:guya ');
  87. $textRun 1 ->getfont ()->setsize ();
  88. $textRun 1 ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' FF000000 ') ) );
  89. $shape 2 = $activeSlide ->createrichtextshape ();
  90. $shape 2 ->setheight (+);
  91. $shape 2 ->setwidth ($);
  92. $shape 2 ->setoffsetx (a);
  93. $shape 2 ->setoffsety (540);
  94. $shape 2 ->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
  95. $shape 2 ->getalignment ()->setvertical (phppowerpoint_style_alignment::vertical_center);
  96. $textRun 2 = $shape 2 ->createtextrun (' date:2009-4-30 ');
  97. $textRun 2 ->getfont ()->setsize ();
  98. $textRun 2 ->getfont ()->setcolor ( new phppowerpoint_style_color ( ' FF000000 ') ) );
  99. //Save pptx file, use 2007 format
  100. $objWriter = Phppowerpoint_iofactory::createwriter ($ppp, ' PowerPoint2007 ') ;
  101. //Save file
  102. $objWriter ->save (ROOT. ' Myphpppt.pptx ' );
  103. Echo ' ppt create success! ' ;
  104. ?>

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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.