Example of creating a PPT document in PHP _ PHP Tutorial

Source: Internet
Author: User
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:

  1. <? Php
  2. /*** PHP generates the PowerPoint 2007 sample script.
    ** This program requires PHP 5.2 or a later version,
    Php_zip and
    Php_xml extension support.
  3. * In Windows, you only need to open the php_zip extension,
    Php_xml extension built-in support.
  4. * In Linux, it must be adjusted according to the compiling conditions.
  5. ** @ Author: Guya
  6. * @ Since: 2009-4-30
  7. */
  8. // Directory delimiter
  9. Define ('Ds', DIRECTORY_SEPARATOR );
  10. // Define the root directory
  11. Define ('root', dirname (_ FILE _). DS );
  12. // Modify the include path, PHPPowerPoint
    Put the package in the libs Directory of the current directory.
  13. Set_include_path (get_include_path ().
    PATH_SEPARATOR. ROOT. 'libs ');
  14. // The script running time is not limited.
  15. Set_time_limit (0 );
  16. // Set the automatic loading function.
  17. Function _ autoload ($ className)
    {Include_once (str_replace ("_", DS,
    $ ClassName). ". php ");}
  18. // Create a PHPPowerPoint object.
  19. $ Ppp = new PHPPowerPoint ();
  20. // Obtain the current slide
  21. $ ActiveSlide = $ ppp->GetActiveSlide ();
  22. // Add an image to the slide.
  23. $ Shape = $ activeSlide->CreateDrawingShape ();
  24. // Set the image name.
  25. $ Shape->SetName ('mmclub. net Logo ');
  26. // Set the description of the image.
  27. $ Shape->SetDescription ('mmclub. net Logo ');
  28. // Actual Image path
  29. $ Shape->SetPath (ROOT. 'mmclub.net.jpg ');
  30. // Image height
  31. $ Shape->SetHeight (103 );
  32. // Set the image width
  33. $ Shape->SetWidth (339 );
  34. // Set the position of the image in pixels relative to the X position in the upper left corner.
  35. $ Shape->SetOffsetX (10 );
  36. // Sets the position of the image in pixels relative to Y in the upper left corner.
  37. $ Shape->SetOffsetY (10 );
  38. // Set the graph display status
  39. $ Shape->GetShadow ()->SetVisible (true );
  40. $ Shape->GetShadow ()->SetDirection (45 );
  41. $ Shape->GetShadow ()->SetDistance (10 );
  42. // Set a text box
  43. $ Shape = $ activeSlide->CreateRichTextShape ();
  44. // Set the text box height, in pixels
  45. $ Shape->SetHeight (150 );
  46. // Set the text box width, in pixels
  47. $ Shape->SetWidth (600 );
  48. // Set the position of the text box in pixels relative to the X position in the upper left corner.
  49. $ Shape->SetOffsetX (150 );
  50. // Set the position in pixels of the text box relative to Y in the upper left corner.
  51. $ Shape->SetOffsetY (200 );
  52. // Set the text layout to horizontal center and vertical center.
  53. $ Shape->GetAlignment ()->SetHorizontal (
    PHPPowerPoint_Style_Alignment: HORIZONTAL_CENTER );
  54. $ Shape->GetAlignment ()->SetVertical (
    PHPPowerPoint_Style_Alignment: VERTICAL_CENTER );
  55. // 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.
  56. $ TextRun = $ shape->CreateTextRun (
    'Welcome to PHPPowerPoint2007 ');
  57. // Bold with font
  58. $ TextRun->GetFont ()->SetBold (true );
  59. // 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
  60. $ TextRun->GetFont ()->SetSize (38 );
  61. // 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.
  62. $ TextRun->GetFont ()->SetColor (new
    PHPPowerPoint_Style_Color ('ffff000000 '));
  63. // Set several text boxes below
  64. $ Shape0 = $ activeSlide->CreateRichTextShape ();
  65. $ Shape0->SetHeight (50 );
  66. $ Shape0->SetWidth (400 );
  67. $ Shape0->SetOffsetX (250 );
  68. $ Shape0->SetOffsetY (400 );
  69. $ Shape0->GetAlignment ()->SetHorizontal (
    PHPPowerPoint_Style_Alignment: HORIZONTAL_CENTER );
  70. $ Shape0->GetAlignment ()->SetVertical
    (PHPPowerPoint_Style_Alignment: VERTICAL_CENTER );
  71. $ TextRun0 = $ shape0->CreateTextRun ('http:
    // Www.mmclub.net ');
  72. $ TextRun0->GetFont ()->SetSize (26 );
  73. $ TextRun0->GetFont ()->SetColor (new
    PHPPowerPoint_Style_Color ('ff0000ff '));
  74. $ Shape1 = $ activeSlide->CreateRichTextShape ();
  75. $ Shape1->SetHeight (30 );
  76. $ Shape1->SetWidth (200 );
  77. $ Shape1->SetOffsetX (700 );
  78. $ Shape1->SetOffsetY (500 );
  79. $ Shape1->GetAlignment ()->SetHorizontal (
    PHPPowerPoint_Style_Alignment: HORIZONTAL_LEFT );
  80. $ Shape1->GetAlignment ()->SetVertical (
    PHPPowerPoint_Style_Alignment: VERTICAL_CENTER );
  81. $ TextRun1 = $ shape1->CreateTextRun ('Author: Guya ');
  82. $ TextRun1->GetFont ()->SetSize (14 );
  83. $ TextRun1->GetFont ()->SetColor (new
    PHPPowerPoint_Style_Color ('ff000000 '));
  84. $ Shape2 = $ activeSlide->CreateRichTextShape ();
  85. $ Shape2->SetHeight (30 );
  86. $ Shape2->SetWidth (200 );
  87. $ Shape2->SetOffsetX (700 );
  88. $ Shape2->SetOffsetY (540); $ shape2->GetAlignment ()->
    SetHorizontal (PHPPowerPoint_Style_Alignment ::
    HORIZONTAL_LEFT );
  89. $ Shape2->GetAlignment ()->SetVertical (
    PHPPowerPoint_Style_Alignment: VERTICAL_CENTER );
  90. $ TextRun2 = $ shape2->CreateTextRun ('date: 2009-4-30 ');
  91. $ TextRun2->GetFont ()->SetSize (14 );
  92. $ TextRun2->GetFont ()->SetColor (
    New PHPPowerPoint_Style_Color ('ff000000 '));
  93. // Save the PPTX file in 2007 format
  94. $ ObjWriter = PHPPowerPoint_IOFactory ::
    CreateWriter ($ ppp, 'powerpoint2007 ');
  95. // Save the file
  96. $ ObjWriter->Save (ROOT. 'myPhpPpt.pptx ');
  97. Echo 'ppt create success! ';
  98. ?>

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...

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.