Skip to content

This package replaces pre-defined variables in presentations with data

Notifications You must be signed in to change notification settings

workdevelop/PresentationReplacer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PRESENTATION REPLACER

Annotation

This package replaces pre-defined variables in presentations with data This package is suitable not only for vitalize presentation templates, but also for any other zip archives with files, contained pre-defined strings printing_args

Example

File example.pptx is template and has pre-defined variables at some src file
chart2_datatype1_0, chart2_datatype1_1, chart2_datatype1_2 like this

Preparation

$createPresentation = new \PresentationReplacer\CreatePresentation();
$templatePath = __DIR__.'/../storage/example.pptx';
$resultPath = __DIR__.'/../storage/result/result'.date('Ymd_His').'.pptx';
$createPresentation->setTemplatePath($templatePath);
$createPresentation->setResultPath($resultPath);
$createPresentation->setVariableRegex('/(\{char.*?\})/');

Get pre-defined variables at presentation

try {
    $allVariables = $createPresentation->getAllVariablesAtPresentation();
} catch (PresentationReplacer\PptException $exception) {
    //do something
}

To replace pre-defined variable real data and download

try {
    $createPresentation->replaceVariables([
        '{chart2_datatype1_0}' => 500,
        '{chart2_datatype1_1}' => 501
        '{chart2_datatype1_2}' => 100
    ]);
} catch (PresentationReplacer\PptException $exception) {
    //do something
}
$createPresentation->download('ready_presentation.pptx');

Get file content at presentation

try {
    $chartContent = $createPresentation->getFileContentByRelativePath('ppt/charts/chart1.xml');
} catch (\PresentationReplacer\PptException $exception) {
    //do something
}

Set file content at presentation

try {
    $createPresentation->setFileContentByRelativePath('ppt/charts/chart1.xml', $chartContent);
} catch (\PresentationReplacer\PptException $exception) {
    //do something
}

If you need replace file by Path, such as image
You know relative file pat which was replaced('ppt/media/image2.png')
And you have Absolute path to file where is new image located

$logoPath = __DIR__.'/../storage/image.png';
try {
    $createPresentation->setFileContentByRelativePath('ppt/media/image2.png', $logoPath);
} catch (\PresentationReplacer\PptException $exception) {
    //do something
}

How to prepare presentation template

coming soon

About

This package replaces pre-defined variables in presentations with data

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages