Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Problema con PhpOffice\PhpPresentation

    ciao!

    ho installato tramite composer PhpOffice\PhpPresentation.
    poi ho creato uno script con il contenuto che ho trovato su github, racchiuso in try/catch:
    codice:
    require_once 'lib/vendor/autoload.php';
    
    use PhpOffice\PhpPresentation\PhpPresentation;
    use PhpOffice\PhpPresentation\IOFactory;
    use PhpOffice\PhpPresentation\Style\Color;
    use PhpOffice\PhpPresentation\Style\Alignment;
    
    try {
        $objPHPPowerPoint = new PhpPresentation();
    
        $currentSlide = $objPHPPowerPoint->getActiveSlide();
    
    // Create a shape (drawing)
        $shape = $currentSlide->createDrawingShape();
        $shape->setName('PHPPresentation logo')
            ->setDescription('PHPPresentation logo')
    //    ->setPath('./resources/phppowerpoint_logo.gif')
            ->setHeight(36)
            ->setOffsetX(10)
            ->setOffsetY(10);
        $shape->getShadow()->setVisible(true)
            ->setDirection(45)
            ->setDistance(10);
    
    // Create a shape (text)
        $shape = $currentSlide->createRichTextShape()
            ->setHeight(300)
            ->setWidth(600)
            ->setOffsetX(170)
            ->setOffsetY(180);
        $shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
        $textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
        $textRun->getFont()->setBold(true)
            ->setSize(60)
            ->setColor(new Color('FFE06B20'));
    
        $oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
        $oWriterPPTX->save(__DIR__ . "/sample.pptx");
        $oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
        $oWriterODP->save(__DIR__ . "/sample.odp");
    } catch (Exception $ex) {
        echo $ex->getMessage();
    }
    sulla pagina ottengo questo errore: The file "" doesn't exist

    qualche idea??

  2. #2
    ho attivato gli errori sul server e questo è quello che mi da:
    codice:
    Fatal error:  Uncaught  PhpOffice\PhpPresentation\Exception\FileNotFoundException: The file ""  doesn't exist in  /home/nvuasusi/public_html/api/lib/vendor/phpoffice/phppresentation/src/PhpPresentation/Shape/Drawing/File.php:85 Stack trace: #0  /home/nvuasusi/public_html/api/lib/vendor/phpoffice/phppresentation/src/PhpPresentation/Writer/PowerPoint2007/ContentTypes.php(133):  PhpOffice\PhpPresentation\Shape\Drawing\File->getMimeType() #1  /home/nvuasusi/public_html/api/lib/vendor/phpoffice/phppresentation/src/PhpPresentation/Writer/PowerPoint2007.php(124):   PhpOffice\PhpPresentation\Writer\PowerPoint2007\ContentTypes->render() #2 /home/nvuasusi/public_html/api/test.php(39):  PhpOffice\PhpPresentation\Writer\PowerPoint2007->save() #3 {main}   thrown in /home/nvuasusi/public_html/api/lib/vendor/phpoffice/phppresentation/src/PhpPresentation/Shape/Drawing/File.php on line 85

  3. #3
    ok capito il problema, la riga commentata con il logo.
    decommentandola, e dandogli il path corretto, funziona tutto.
    codice:
    <?php
    
    require_once 'lib/vendor/autoload.php';
    
    use PhpOffice\PhpPresentation\PhpPresentation;
    use PhpOffice\PhpPresentation\IOFactory;
    use PhpOffice\PhpPresentation\Style\Color;
    use PhpOffice\PhpPresentation\Style\Alignment;
    
    $objPHPPresentation = new PhpPresentation();
    
    $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
        ->setLastModifiedBy('PHPPresentation Team')
        ->setTitle('Sample 01 Title')
        ->setSubject('Sample 01 Subject')
        ->setDescription('Sample 01 Description')
        ->setKeywords('office 2007 openxml libreoffice odt php')
        ->setCategory('Sample Category');
    
    $currentSlide = $objPHPPresentation->getActiveSlide();
    
    $shape = $currentSlide->createDrawingShape();
    $shape->setName('PHPPresentation logo')
        ->setDescription('PHPPresentation logo')
    //    ->setPath('./assets/rome-and-italy-tours-logo.png')
        ->setHeight(36)
        ->setOffsetX(10)
        ->setOffsetY(10);
    $shape->getShadow()->setVisible(true)
        ->setDirection(45)
        ->setDistance(10);
    
    $shape = $currentSlide->createRichTextShape()
        ->setHeight(300)
        ->setWidth(600)
        ->setOffsetX(170)
        ->setOffsetY(100);
    $shape->getActiveParagraph()->getAlignment()
        ->setHorizontal(Alignment::HORIZONTAL_CENTER);
    $textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
    $textRun->getFont()->setBold(true)
        ->setSize(60)
        ->setColor(new Color('FFE06B20'));
    
    $oWriterPPTX = IOFactory::createWriter($objPHPPresentation, 'PowerPoint2007');
    header("Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation");
    header("Content-Disposition: attachment; filename=test.pptx");
    $oWriterPPTX->save('php://output');

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.