xISRAPILx
@xISRAPILx
Кратко не получится

Как исправить потерю макета в PHPPresentation?

Нужно объединить большое количество презентаций в одну используя PHP.
Для работы с презентациями выбрал PHPPresentation, т.к не нашел аналогов(а может просто плохо искал) и наткнулся на проблему. Конечный файл теряет половину макета.
Код:
spoiler
<?php /** @noinspection SpellCheckingInspection */

use PhpOffice\PhpPresentation\Autoloader as PresentationAutoloader;
use PhpOffice\Common\Autoloader as OfficeAutoloader;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\PhpPresentation;

abstract class MergePresentations{

    const POWERPOINT2007 = "PowerPoint2007";
    const POWERPOINT97 = "PowerPoint97";
    const ODPRESENTATION = "ODPresentation";

    /**
     * @param array $presentationFiles Массив с ссылками на файлы презентаций
     * @param string $outputFile Путь к выходному файлу
     * @param string $presentationReaderType
     * @param bool $fileSensitive Выкидывает исключение, если файл не найден при <code>$fileSensitive==true</code>
     *
     * @throws FileNotFoundException
     * @throws Exception
     */
    public static function merge(array $presentationFiles, string $outputFile, string $presentationReaderType = self::POWERPOINT2007, bool $fileSensitive = false){
        require_once "PhpPresentation/Autoloader.php";
        PresentationAutoloader::register();

        require_once "Common/Autoloader.php";
        OfficeAutoloader::register();

        $presentationReader = IOFactory::createReader($presentationReaderType);

        /** @var PhpPresentation $outputPresentation */
        $outputPresentation = null;
        foreach($presentationFiles as $presentationFile){
            if(file_exists($presentationFile)){
                $presentation = $presentationReader->load($presentationFile);

                if($outputPresentation === null){
                    $outputPresentation = $presentation;

                    continue;
                }

                foreach($presentation->getAllSlides() as $slide){
                    $outputPresentation->addExternalSlide($slide);
                }
            }else{
                if($fileSensitive){
                    throw new FileNotFoundException("File ".$presentationFile." not found!");
                }
            }
        }

        if($outputPresentation !== null){
            $presentationWriter = IOFactory::createWriter($outputPresentation, $presentationReaderType);
            $presentationWriter->save($outputFile);
        }
    }
}

class FileNotFoundException extends Exception{}

Один из исходных слайдов:
spoiler
5e493a062b699975446262.png

Один из конечных слайдов:
spoiler
5e4939ab48d02048037005.png

Все слайды, в данном случае, оформлены одним макетом, но даже так всё ломается.
  • Вопрос задан
  • 88 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы