general.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .. _general:
  2. General usage
  3. =============
  4. Basic example
  5. -------------
  6. The following is a basic example of the PHPPresentation library. More examples
  7. are provided in the `samples
  8. folder <https://github.com/PHPOffice/PHPPresentation/tree/master/samples/>`__.
  9. .. code-block:: php
  10. require_once 'src/PhpPresentation/Autoloader.php';
  11. \PhpOffice\PhpPresentation\Autoloader::register();
  12. $objPHPPresentation = new PhpPresentation();
  13. // Create slide
  14. $currentSlide = $objPHPPresentation->getActiveSlide();
  15. // Create a shape (drawing)
  16. $shape = $currentSlide->createDrawingShape();
  17. $shape->setName('PHPPresentation logo')
  18. ->setDescription('PHPPresentation logo')
  19. ->setPath('./resources/phppresentation_logo.gif')
  20. ->setHeight(36)
  21. ->setOffsetX(10)
  22. ->setOffsetY(10);
  23. $shape->getShadow()->setVisible(true)
  24. ->setDirection(45)
  25. ->setDistance(10);
  26. // Create a shape (text)
  27. $shape = $currentSlide->createRichTextShape()
  28. ->setHeight(300)
  29. ->setWidth(600)
  30. ->setOffsetX(170)
  31. ->setOffsetY(180);
  32. $shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
  33. $textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
  34. $textRun->getFont()->setBold(true)
  35. ->setSize(60)
  36. ->setColor( new Color( 'FFE06B20' ) );
  37. $oWriterPPTX = IOFactory::createWriter($objPHPPresentation, 'PowerPoint2007');
  38. $oWriterPPTX->save(__DIR__ . "/sample.pptx");
  39. $oWriterODP = IOFactory::createWriter($objPHPPresentation, 'ODPresentation');
  40. $oWriterODP->save(__DIR__ . "/sample.odp");
  41. Document information
  42. --------------------
  43. You can set the document information such as title, creator, and company
  44. name. Use the following functions :
  45. .. code-block:: php
  46. $properties = $objPHPPresentation->getProperties();
  47. $properties->setCreator('My name');
  48. $properties->setCompany('My factory');
  49. $properties->setTitle('My title');
  50. $properties->setDescription('My description');
  51. $properties->setCategory('My category');
  52. $properties->setLastModifiedBy('My name');
  53. $properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
  54. $properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
  55. $properties->setSubject('My subject');
  56. $properties->setKeywords('my, key, word');
  57. Presentation Properties
  58. -----------------------
  59. You can define some properties which are relative to the presentation, like the zoom or the thumbnail.
  60. Comments
  61. ````````
  62. You can define if the presentation display or not the comments with the method ``setCommentVisible``.
  63. .. code-block:: php
  64. $oPresentation = new PhpPresentation();
  65. $oProperties = $oPresentation->getPresentationProperties();
  66. // Get the display for comment
  67. var_export($oProperties->isCommentVisible());
  68. // Output : false
  69. // Enable the display for comment
  70. $oProperties->setCommentVisible(true);
  71. // Get the display for comment
  72. var_export($oProperties->isCommentVisible());
  73. // Output : true
  74. Last View
  75. `````````
  76. You can define the last view of the presentation with the method ``setLastView``.
  77. .. code-block:: php
  78. $oPresentation = new PhpPresentation();
  79. $oProperties = $oPresentation->getPresentationProperties();
  80. // Get the last view of the presentation
  81. echo $oProperties->getZoom();
  82. // Output : PresentationProperties::VIEW_SLIDE
  83. // Set the last view of the presentation
  84. $oProperties->setLastView(PresentationProperties::VIEW_NOTES);
  85. // Get the last view of the presentation
  86. echo $oProperties->getZoom();
  87. // Output : PresentationProperties::VIEW_NOTES
  88. Thumbnail
  89. `````````
  90. You can define the thumbnail of the presentation with the method ``setThumbnailPath``.
  91. .. code-block:: php
  92. $oPresentation = new PhpPresentation();
  93. $oProperties = $oPresentation->getPresentationProperties();
  94. // Set path of the thumbnail
  95. $oProperties->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
  96. // Get path of the thumbnail
  97. echo $oProperties->getThumbnailPath();
  98. Zoom
  99. ````
  100. You can define the zoom of the presentation with the method ``setZoom``.
  101. .. code-block:: php
  102. $oPresentation = new PhpPresentation();
  103. $oProperties = $oPresentation->getPresentationProperties();
  104. // Get zoom of the presentation
  105. echo $oProperties->getZoom();
  106. // Output : 1
  107. // Set zoom of the presentation (3 = 300%)
  108. $oProperties->setZoom(3);
  109. // Get zoom of the presentation
  110. echo $oProperties->getZoom();
  111. // Output : 3