Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generating a PPT file using a template with placeholders getting the error "getIndex() on null" #804

Open
arulselvan008 opened this issue Jun 3, 2024 · 1 comment

Comments

@arulselvan008
Copy link

arulselvan008 commented Jun 3, 2024

public function generatePresentationAction()
    {
        $presentation = new PhpPresentation();
        $productName = "NewProduct";
        $sku = "Test01";
    
        $templatePath = '/home/pim_svc/b.pptx';
        $templatePresentation = IOFactory::createReader('PowerPoint2007')->load($templatePath);
        $masterSlides = $templatePresentation->getAllMasterSlides();
        foreach ($masterSlides as $masterSlide) {
            $slideLayouts = $masterSlide->getAllSlideLayouts();
            
            foreach ($slideLayouts as $slideLayout) {
                $slide = new Slide();
                $slide->setShapeCollection($slideLayout->getShapeCollection());
                $presentation->addSlide($slide);
                $shapes = $slide->getShapeCollection();
                foreach ($shapes as $shape) {
                    if ($shape instanceof RichText) {
                        $text = $shape->getPlainText();

                        if (stripos($text, 'PRODUCTNAME')!== false) {
                            $shape->getActiveParagraph()->getRichTextElements()[0]->setText(str_replace('PRODUCTNAME', $productName, $text));
                        }
                        // if (stripos($text, 'SKU')!== false) {
                        //     $shape->getActiveParagraph()->getRichTextElements()[0]->setText(str_replace('SKU', $sku, $text));
                        // }
                    }
                }
            }
        }
        
        $filename = "newOutPUT".'.pptx';
        // $tmpFilename = sys_get_temp_dir(). '/'. $filename;
        $writer = IOFactory::createWriter($presentation, 'PowerPoint2007');
        $writer->save($filename);
        
        $response = new BinaryFileResponse($tmpFilename);
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
    
        return $response;
    }

For your reference my code above, I am trying to generate a PPT file based on a sample template with placeholders, but I am getting an error: "Call to a member function getIndex() on null." How can I fix this? Can anyone help me resolve this issue?

Error
b.pptx
b.pptx

@arulselvan008 arulselvan008 changed the title getIndex() on null error generating a PPT file using a template with placeholders getting the error "getIndex() on null" Jun 3, 2024
@arulselvan008
Copy link
Author

Hi, does anyone have an idea about these queries? Please help us resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants