PHPOffice / PHPPresentation

A pure PHP library for reading and writing presentations documents
https://phpoffice.github.io/PHPPresentation
Other
1.31k stars 523 forks source link

can't merge 2 pptx files #368

Open delia-curiel opened 7 years ago

delia-curiel commented 7 years ago

Hi, I can't merge two pptx files into one. The result pptx has all slides in blank. Here is my code:

    $oPHPPresentation = new PhpPresentation();

    $oReader1 = IOFactory::createReader('PowerPoint2007');
    $oPHPPresentation1 = $oReader1->load(storage_path('app/diapositiva1.pptx'));
    $c = $oPHPPresentation1->getSlideCount();
    for($i=0; $i<$c; $i++)
        $oPHPPresentation->addExternalSlide($oPHPPresentation1->getSlide($i));

    $oReader2 = IOFactory::createReader('PowerPoint2007');
    $oPHPPresentation2= $oReader2->load(storage_path('app/diapositiva2.pptx'));
    $c = $oPHPPresentation2->getSlideCount();
    for($i=0; $i<$c; $i++)
        $oPHPPresentation->addExternalSlide($oPHPPresentation2->getSlide($i));

    $oWriterPPTX = IOFactory::createWriter($oPHPPresentation, 'PowerPoint2007');
    $oWriterPPTX->save(storage_path("app/merged.pptx"));
dookieffs commented 7 years ago

any update on this? lost most of the formatting when I tried to read previously generated pptx by phpPresentation

Progi1984 commented 7 years ago

@delia-curiel or @dookieffs Have you got two pptx in error to share ?

alvar0hurtad0 commented 6 years ago

I've the same problem.

This code should do the job:

    $ppt_reader = IOFactory::createReader('PowerPoint2007');

    // Create destination and add all slides.
    $destination = new PhpPresentation();
    // The first slide is empty as it's added on the create operation.
    $destination->removeSlideByIndex(0);

    foreach ($this->souce_slides as $souce_slide) {
      $file = drupal_realpath($souce_slide);
      $sourceSlideShow = $ppt_reader->load($file);

      foreach ($sourceSlideShow->getAllSlides() as $oSlide) {
        $destination->addExternalSlide($oSlide);
      }
    }

    $xmlWriter = IOFactory::createWriter($destination, 'PowerPoint2007');

Even with just one pptx file, the result doen't have some text boxes.

Source:

source.pptx

Result

result.pptx