Example of creating a PPT document in PHP. PHP creates a PPT document code instance :? Php *** PHP generates the PowerPoint2007 sample script. ** This program requires PHP5.2 and later versions, and php_zip and php_xml extensions are required. * generally, in windows
PHP:
- <? Php
- /*** PHP generates the PowerPoint 2007 sample script.
** This program requires PHP 5.2 or a later version,
Php_zip and
Php_xml extension support.
- * In Windows, you only need to open the php_zip extension,
Php_xml extension built-in support.
- * In Linux, it must be adjusted according to the compiling conditions.
- ** @ Author: Guya
- * @ Since: 2009-4-30
- */
- // Directory delimiter
- Define ('Ds', DIRECTORY_SEPARATOR );
- // Define the root directory
- Define ('root', dirname (_ FILE _). DS );
- // Modify the include path, PHPPowerPoint
Put the package in the libs Directory of the current directory.
- Set_include_path (get_include_path ().
PATH_SEPARATOR. ROOT. 'libs ');
- // The script running time is not limited.
- Set_time_limit (0 );
- // Set the automatic loading function.
- Function _ autoload ($ className)
{Include_once (str_replace ("_", DS,
$ ClassName). ". php ");}
- // Create a PHPPowerPoint object.
- $ Ppp = new PHPPowerPoint ();
- // Obtain the current slide
- $ ActiveSlide = $ ppp->GetActiveSlide ();
- // Add an image to the slide.
- $ Shape = $ activeSlide->CreateDrawingShape ();
- // Set the image name.
- $ Shape->SetName ('mmclub. net Logo ');
- // Set the description of the image.
- $ Shape->SetDescription ('mmclub. net Logo ');
- // Actual Image path
- $ Shape->SetPath (ROOT. 'mmclub.net.jpg ');
- // Image height
- $ Shape->SetHeight (103 );
- // Set the image width
- $ Shape->SetWidth (339 );
- // Set the position of the image in pixels relative to the X position in the upper left corner.
- $ Shape->SetOffsetX (10 );
- // Sets the position of the image in pixels relative to Y in the upper left corner.
- $ Shape->SetOffsetY (10 );
- // Set the graph display status
- $ Shape->GetShadow ()->SetVisible (true );
- $ Shape->GetShadow ()->SetDirection (45 );
- $ Shape->GetShadow ()->SetDistance (10 );
- // Set a text box
- $ Shape = $ activeSlide->CreateRichTextShape ();
- // Set the text box height, in pixels
- $ Shape->SetHeight (150 );
- // Set the text box width, in pixels
- $ Shape->SetWidth (600 );
- // Set the position of the text box in pixels relative to the X position in the upper left corner.
- $ Shape->SetOffsetX (150 );
- // Set the position in pixels of the text box relative to Y in the upper left corner.
- $ Shape->SetOffsetY (200 );
- // Set the text layout to horizontal center and vertical center.
- $ Shape->GetAlignment ()->SetHorizontal (
PHPPowerPoint_Style_Alignment: HORIZONTAL_CENTER );
- $ Shape->GetAlignment ()->SetVertical (
PHPPowerPoint_Style_Alignment: VERTICAL_CENTER );
- // Set text content in the text box. no Chinese problems are detected in the Chinese environment.
In the e-file environment, you must specify fonts that support Chinese characters.
Otherwise, garbled characters may occur.
- $ TextRun = $ shape->CreateTextRun (
'Welcome to PHPPowerPoint2007 ');
- // Bold with font
- $ TextRun->GetFont ()->SetBold (true );
- // Set the font size to 38. pay attention to the text size settings here.
The size of the text box is fixed. if the text exceeds
Containers will be excluded from the container
- $ TextRun->GetFont ()->SetSize (38 );
- // Set the text color. here the ARGB mode and hexadecimal mode are used,
The first two digits are transparency, followed by RGB values. here they are set to blue.
- $ TextRun->GetFont ()->SetColor (new
PHPPowerPoint_Style_Color ('ffff000000 '));
- // Set several text boxes below
- $ Shape0 = $ activeSlide->CreateRichTextShape ();
- $ Shape0->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 the PPTX file in 2007 format
- $ ObjWriter = PHPPowerPoint_IOFactory ::
CreateWriter ($ ppp, 'powerpoint2007 ');
- // Save the file
- $ ObjWriter->Save (ROOT. 'myPhpPpt.pptx ');
- Echo 'ppt create success! ';
- ?>
The application prospect of this php ppt document is useful in some WEB scenarios. you can spend more time studying it.
Why :? Php/*** PHP generate the PowerPoint2007 sample script. *** this program requires PHP5.2 and later versions, and php_zip and php_xml extensions are required. * generally, in Windows, you only need to input...