Code example for creating PPT document with PHP:
- < ?php
- / *** PHP generates PowerPoint 2007 sample script.
* * This program requires PHP 5.2 or above,
requires php_zip and
php_xml extension support. - * Usually under WIN The program only needs to open the php_zip extension.
The php_xml extension has built-in support. - * Under Linux, specific adjustments need to be made according to the compilation conditions.
- * * @author: Guya
- * @since: 2009-4-30
- */
- //Directory separation symbol
- define('DS', DIRECTORY_SEPARATOR);
- //Define the root directory
- define('ROOT', dirname(__FILE__) . DS);
- //Modify the include path, PHPPowerPoint
package is placed in the libs directory of the current directory. - set_include_path(get_include_path() .
PATH_SEPARATOR . ROOT . 'libs'); - //No limit on script running time.
- set_time_limit(0);
- //Simple setting of autoload function.
- function __autoload($className)
{ include_once(str_replace("_", DS,
$className) . ".php"); } - //Create a new PHPPowerPoint object.
- $ppp = new PHPPowerPoint();
- //Get the currently used slideshow
- $activeSlide = $ppp->getActiveSlide();
- //Add a picture to the slide. >
shape-
= $activeSlide->createDrawingShape() ; //Set the image name.
- $shape-
- >setName('MmClub.net Logo'); //Set the description information of the picture. 🎜>$shape-
- >
- setDescription('MmClub.net Logo'); //The actual path of the image $shape-
- >
- setPath (ROOT . 'mmclub.net.jpg'); //Picture height $shape-
- >
- setHeight(103); //Set image width $shape-
- >
- setWidth(339); / /Set the X position of the picture relative to the upper left corner, unit pixel $shape-
- >
- setOffsetX(10); //Set the Y position of the image relative to the upper left corner, unit pixels $shape-
- >
- setOffsetY(10); $shape->
getShadow()- >-
setVisible(true); >getShadow()->setDirection(45);
$shape--
>getShadow()- >setDistance(10);
//Set a text box -
$shape = $activeSlide->createRichTextShape();
- //Set text box height, unit pixels
-
$shape->setHeight(150); //Set the text box width in pixels
$shape- >-
setWidth(600); //Set the X position of the text box relative to the upper left corner, unit pixels
$shape- >-
setOffsetX(150); //Set the Y position of the text box relative to the upper left corner, unit pixels
$shape- >-
setOffsetY(200);
- //Set the text layout position to be horizontally centered and vertically centered.
-
$shape->getAlignment()->setHorizontal(
PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ) ;
-
$shape->getAlignment()->setVertical(
PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
- //Set the text box Text content. There is no Chinese problem when testing in a Chinese environment.
If in an e-text environment, be sure to specify a font that supports Chinese.
Otherwise, garbled characters may appear. -
$textRun = $shape-> createTextRun(
'Welcome to PHPPowerPoint2007');
- //Use font bold
-
$textRun->getFont()->setBold(true);
- //Set the font size to 38, pay attention to the text size setting here.
The size of the previous text box is fixed. If the text exceeds The
container will be out of the container and queued to the bottom -
$textRun->getFont()->setSize(38);
- //Set text color, here is ARGB mode, hexadecimal mode,
The first 2 digits are transparency, and the back is RGB value. Here is set to blue -
$ textRun->getFont()->setColor( new
PHPPowerPoint_Style_Color( 'FFFF0000' ) );
- //Set a few more text boxes below
-
$shape0 = $activeSlide->createRichTextShape(); setHeight(50);
-
$shape0->setWidth(400) ;
-
$shape0->setOffsetX(250);
-
$shape0->setOffsetY(400);
-
$shape0->getAlignment()-
-
>setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $shape0->
getAlignment()-
-
>setVertical ( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); $textRun0 = $shape0-
>-
createTextRun('http://www.mmclub.net');
-
$textRun0->getFont()->setSize(26);
-
$textRun0->getFont()->setColor( new
PHPPowerPoint_Style_Color( 'FF0000FF' ) );
-
$shape1 = $activeSlide->createRichTextShape();
-
$shape1->setHeight(30);
-
$shape1->setWidth(200);
-
$shape1->setOffsetX(700);
-
$shape1->setOffsetY(500);
-
$shape1->getAlignment()->setHorizontal(
PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );
-
$shape1->getAlignment()->setVertical(
PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
-
$textRun1 = $shape1->createTextRun('Author: Guya');
-
$textRun1->getFont()->setSize(14);
-
$textRun1->getFont()->setColor( new
PHPPowerPoint_Style_Color( 'FF000000' ) );
-
$shape2 = $activeSlide->createRichTextShape();
-
$shape2->setHeight(30);
-
$shape2->setWidth(200);
-
$shape2->setOffsetX(700);
-
$shape2->setOffsetY(540); $shape2->getAlignment()->
setHorizontal( PHPPowerPoint_Style_Alignment::
HORIZONTAL_LEFT );
-
$shape2->getAlignment()->setVertical(
PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
-
$textRun2 = $shape2->createTextRun('Date: 2009-4-30');
-
$textRun2->getFont()->setSize(14);
-
$textRun2->getFont( )->setColor(
new PHPPowerPoint_Style_Color( 'FF000000' ) );
- //Save PPTX file, using 2007 format
-
$objWriter = PHPPowerPoint_IOFactory::
createWriter($ppp, 'PowerPoint2007');
- //Save the file
-
$objWriter->save(ROOT . 'myPhpPpt.pptx');
- echo 'ppt create success!'; >
-
As for the application prospects of creating PPT documents with PHP, it is still very useful in some WEB situations. Friends who need it can spend more time to study it.
http://www.bkjia.com/PHPjc/445942.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/445942.html
TechArticle
Code example for creating PPT document with PHP: ?php /***PHP generates PowerPoint2007 sample script. **This program requires PHP5.2 or above requires php_zip and php_xml extension support. *Usually, the program under WIN only needs to open...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn