Forum


Replies: 1   Views: 148
A few questions from a possible user.
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phppptx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phppptx version and check the Documentation available.

Posted by avandoorine  · 31-07-2024 - 14:33

Hello.

I'm investigating the possibility to use phppptx on our platform, as well as your others products. 
So my first stop as we are in the process of making this evaluation was phpdocx, which works superbly as far as the trial went and the unlocked features. 
So while we do not support Powerpoint exports right now it seems a good idea to look into phppptx.

So here are two use cases that I'm trying to apply without success with the Template part.

1/ I'm using the replace HTML function, and while using it I noticed it would not accept much less things than in Word. For example no line return and no images. 
Is that a current limitation (as I see the functionannly was added in 2.5), or is it something definitive.

2/ The other use case is to replace a tag via multiple images. To do this with phpdocx I'm using a Fragment and add multiple images to it then replace it with the function for this operation. 
In phppptx, if I create a fragment and add an Image to it there is a crash with the following error : 
"Fatal error: Uncaught Error: Call to a member function getSlides() on null in F:\temp\word\phppptx\classes\CreatePptx.php:1241"

The code is looking like this : 

<?php
require_once("phppptx/classes/CreatePptx.php");

$pptx= new CreatePptxFromTemplate('f:\template.pptx');
$pptx->setTemplateSymbol('${', '}');

$pptxFragment = new PptxFragment();
$pptxFragment->addImage('image1.jpg', []);
$pptxFragment->addImage('image2.jpg', []);

$pptx->replaceVariablePptxFragment(['multiple_images' => $pptxFragment], ['type' => 'inline']);

$docx->savePptx('result.pptx');

Is that something that is impossible ? Because in my use case there can be several pictures, and it's not possible to put placeholders for an unknown number of pictures.

Thanks in advance for your answer.

Posted by admin  · 31-07-2024 - 17:10

Hello,

Please check our answers below:

  • On the addHtml API page, you can read the supported HTML tags and CSS styles. Please note that PPTX files don't support as many content types and styles as DOCX documents because PPTX doesn't support them or they haven't been added in the current stable version. New phppptx stable releases support new HTML tags and CSS styles, and a future release of phppptx will include HTML Extended and CSS Extended as phpdocx includes.

Please note that br tags are supported when transforming HTML to PPTX to do line breaks. From the sample Content s/addHtml/sample_1.php included in the package:

$html = '<style>
    p {
        font-family: Arial;
        font-style: italic;
        text-decoration: underline;
        color: #2CA87A;
    }
</style>
<p>Lorem ipsum with <br>Arial font</p>';
$pptx->addHtml($html, array('placeholder' => array('name' => 'Subtitle 2')));
  • replaceVariablePptxFragment only works with text contents generated with addText (and other methods that generate text contents such as addHtml). Images can't be added using a PptxFragment because these contents require setting a position in a slide. We recommend you check the samples included in the package.

Please note that PPTX contents don't work in the same way as DOCX contents. PPTX contents have some limitations and restrictions, for example, images (and other contents such as videos, audios, tables...) must be added in their own shapes (text and many content types can't be mixed in the same shape). To add images you can use addImage to add new images or replaceVariableImage to replace placeholder images, but a text placeholder can't be replaced with an image. Instead of adding multiple placeholders, you can use addImage as many times as needed.

Regards.