You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-172Lines changed: 9 additions & 172 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
`pptx-automizer` is a Node.js-based PowerPoint (.pptx) generator that automates the manipulation of existing .pptx files. With `pptx-automizer`, you can import your library of .pptx templates, merge templates, and customize slide content. `pptx-automizer` will not write files from scratch, but edit and merge existing pptx files. You can style template slides within PowerPoint, and these templates will be seamlessly integrated into the output presentation. Most of the content can be modified by using callbacks with [xmldom](https://github.com/xmldom/xmldom).
4
4
5
+
If you require to create elements from scratch, `pptx-automizer` wraps around [PptxGenJS](https://github.com/gitbrent/PptxGenJS). Use the powerful syntax of `PptxGenJS` to add dynamic content to your existing .pptx template files.
6
+
5
7
`pptx-automizer` is particularly well-suited for users who aim to manage their own library of .pptx template files, making it an ideal choice for those who work with intricate, well-designed customized layouts. With this tool, any existing slide or even a single element can serve as a data-driven template for generating output .pptx files.
6
8
7
9
This project is accompanied by [automizer-data](https://github.com/singerla/automizer-data). You can use `automizer-data` to import, browse and transform .xlsx- or .sav-data into perfectly fitting graph or table data.
@@ -26,11 +28,9 @@ If you require commercial support for complex .pptx automation, you can explore
26
28
-[As a Package](#as-a-package)
27
29
-[Usage](#usage)
28
30
-[Basic Example](#basic-example)
29
-
-[Load files from buffer/URL](#load-files-from-bufferurl)
30
-
-[How to Select Slides And Shapes](#how-to-select-slides-and-shapes)
31
+
-[How to Select Slides Shapes](#how-to-select-slides-shapes)
31
32
-[Select slide by number and shape by name](#select-slide-by-number-and-shape-by-name)
32
33
-[Select slides by creationId](#select-slides-by-creationid)
33
-
-[Get Shape Info](#get-shape-info)
34
34
-[Find and Modify Shapes](#find-and-modify-shapes)
35
35
-[Modify Text](#modify-text)
36
36
-[Modify Images](#modify-images)
@@ -46,7 +46,6 @@ If you require commercial support for complex .pptx automation, you can explore
46
46
-[Import and modify slide Masters](#import-and-modify-slide-masters)
47
47
-[Track status of automation process](#track-status-of-automation-process)
`pptx-automizer` needs a selector to find the required shape on a template slide. While an imported .pptx file is identified by filename or custom label, there are different ways to address its slides and shapes.
259
233
@@ -379,32 +353,9 @@ If you decide to use the `creationId` method, you are safe to add, remove and re
379
353
380
354
> Please note: PowerPoint is going to update a shape's `creationId` only in case the shape was copied & pasted on a slide with an already existing identical shape `creationId`. If you were copying a slide, each shape `creationId` will be copied, too. As a result, you have unique shape ids, but different slide `creationIds`. If you are now going to paste a shape an such a slide, a new creationId will be given to the pasted shape. As a result, slide ids are unique throughout a presentation, but shape ids are unique only on one slide.
381
355
382
-
## Get Shape Info
383
-
384
-
If you need to find out e.g. a shape's coordinates on a slide or if you quickly want to read the text body, you can run `slide.getElement('Cloud')`:
385
-
386
-
```ts
387
-
pres
388
-
.addSlide('shapes', 2, async (slide) => {
389
-
// Read a shape and print its text fragments:
390
-
const info =awaitslide.getElement('Cloud');
391
-
console.log(info.getText());
392
-
393
-
// Or take a look at the shape's coordinates:
394
-
console.log(info.position);
395
-
396
-
// Dump element xml:
397
-
XmlHelper.dump(info.getXmlElement())
398
-
})
399
-
```
400
-
401
-
Find out how to cross-slide copy properties from one shape to another:
There are basically two ways to access a target shape on a slide:
358
+
There are basically to ways to access a target shape on a slide:
408
359
409
360
-`slide.modifyElement(...)` requires an existing shape on the current slide,
410
361
-`slide.addElement(...)` adds a shape from another slide to the current slide.
@@ -559,39 +510,6 @@ Find out more about formatting cells:
559
510
-[Modify and style table cells](https://github.com/singerla/pptx-automizer/blob/main/__tests__/modify-existing-table.test.ts)
560
511
-[Insert data into table with empty cells](https://github.com/singerla/pptx-automizer/blob/main/__tests__/modify-existing-table-create-text.test.ts)
561
512
562
-
563
-
If you need to add rows or columns in a table with merged cells, you can add tags to your template table to expand it:
564
-
```ts
565
-
slide.modifyElement(
566
-
'NestedTable3',
567
-
modify.setTable(tableData, {
568
-
adjustHeight: false,
569
-
adjustWidth: false,
570
-
expand: [
571
-
{
572
-
// Find a cell containing '{{each:row}}' and
573
-
// clone it 3 times row-wise
574
-
mode: 'row',
575
-
tag: '{{each:row}}',
576
-
count: 3,
577
-
},
578
-
{
579
-
// Find a cell containing '{{each:sub}}' and
580
-
// clone it once column-wise. Merged cells will
581
-
// be cloned as well.
582
-
mode: 'column',
583
-
tag: '{{each:sub}}',
584
-
count: 1,
585
-
},
586
-
],
587
-
}),
588
-
);
589
-
```
590
-
591
-
Please find some examples in the tests:
592
-
-[Expand a table with merged cells](https://github.com/singerla/pptx-automizer/blob/main/__tests__/modify-nested-table.test.ts)
593
-
594
-
595
513
## Modify Charts
596
514
597
515
All data and styles of a chart can be modified. Please note that if your template contains more data than your data object, Automizer will remove these extra nodes. Conversely, if you provide more data, new nodes will be cloned from the first existing one in the template.
@@ -665,37 +583,15 @@ pres
665
583
});
666
584
```
667
585
668
-
## Add Bulleted List
669
-
670
-
You can add a bulleted list to a shape. It is also possible to pass a list of nested arrays of strings.
If you would like to modify elements in a single .pptx file, it is important to know that `pptx-automizer` is not able to directly "jump" to a shape to modify it.
695
591
696
592
This is how it works internally:
697
593
698
-
- Load a root template to append slides to it
594
+
- Load a root template to append slides to
699
595
- (Probably) load root template again to modify slides
700
596
- Load other templates
701
597
- Append a loaded slide to (probably truncated) root template
@@ -727,7 +623,7 @@ const run = async () => {
727
623
// Defining a "name" as second params makes it a little easier
728
624
.load(`SlideWithShapes.pptx`, 'myTemplate');
729
625
730
-
//Get useful information about loaded templates:
626
+
//This is brandnew: get useful information about loaded templates:
@@ -888,11 +784,6 @@ To specify another slideLayout for an added output slide, you need to count slid
888
784
889
785
To add and modify shapes on a slide master, please take a look at [Add and modify shapes](https://github.com/singerla/pptx-automizer#add-and-modify-shapes).
890
786
891
-
If you require to modify slide master backgrounds, please refer to
// Import another slide master and all its slide layouts.
898
789
// Index 1 means, you want to import the first of all masters:
@@ -967,56 +858,6 @@ const automizer = new Automizer({
967
858
});
968
859
```
969
860
970
-
## Create a new modifier
971
-
972
-
If the built-in modifiers of `pptx-automizer` are not sufficient to your task, you can access the target xml elements with [xmldom](https://github.com/xmldom/xmldom). A modifier is a wrapper for such an operation.
973
-
974
-
Let's first take a look at a (simplified) existing modifier: `ModifyTextHelper.content('This is my text')`.
975
-
976
-
```ts
977
-
// "setTextContent" is a function that returns a function.
978
-
// A "label" argument needs to be passed to "setTextContent".
// It is possible to output the xml to console at any time.
995
-
// XmlHelper.dump(element);
996
-
};
997
-
};
998
-
```
999
-
1000
-
This function will construct an anonymous callback function on setup, while the callback function itself will be executed on runtime, when it's up to the target element on a slide.
1001
-
1002
-
You can use the modifier e.g. on adding an element:
// Notice: don't call XmlHelper.dump, just pass it
1010
-
XmlHelper.dump,
1011
-
// 2. Apply modifier from the example above:
1012
-
setTextContent('New text'),
1013
-
XmlHelper.dump,
1014
-
]);
1015
-
});
1016
-
```
1017
-
1018
-
We can wrap any xml modification by such a modifier. If you have a working example and you think it will be useful to others, you are very welcome to fork this repo and send a pull request or simply [post it](https://github.com/singerla/pptx-automizer/issues/new).
1019
-
1020
861
## More examples
1021
862
1022
863
Take a look into [**tests**-directory](https://github.com/singerla/pptx-automizer/blob/main/__tests__) to see a lot of examples for several use cases, e.g.:
@@ -1029,18 +870,14 @@ Take a look into [**tests**-directory](https://github.com/singerla/pptx-automize
If you encounter problems when opening a `.pptx`-file modified by this library, you might worry about PowerPoint not giving any details about the error. It can be hard to find the cause, but there are some things you can check:
1034
874
1035
875
-**Broken relation**: There are still unsupported shape types and `pptx-automizer` wil not copy required relations of those. You can inflate `.pptx`-output and check `ppt/slides/_rels/slide[#].xml.rels`-files to find possible missing files.
1036
876
-**Unsupported media**: You can also take a look at the `ppt/media`-directory of an inflated `.pptx`-file. If you discover any unusual file formats, remove or replace the files by one of the [known types](https://github.com/singerla/pptx-automizer/blob/main/src/enums/content-type-map.ts).
1037
877
-**Broken animation**: Pay attention to modified/removed shapes which are part of an animation. In case of doubt, (temporarily) remove all animations from your template. (see [#78](https://github.com/singerla/pptx-automizer/issues/78))
1038
878
-**Proprietary/Binary contents** (e.g. ThinkCell): Walk through all slides, slideMasters and slideLayouts and seek for hidden Objects. Hit `ALT+F10` to toggle the sidebar.
1039
-
-**Chart styles not working**: If you try to change e.g. color or size of a chart data label, and it doesn't work as expected, try to remove all data labels and activate them again. If this does not help, try to give the first data label of a series a slightly different style (this creates a single data point).
1040
-
-**Replace Text not working**: Disable spell checking for the whole tag; If this doesn't help, cut out your e.g. {CustomerName} tag from textbox to clipboard, paste it into a plaintext editor to remove all (visible and invisible) formatting. Copy & paste {CustomerName} back to the textbox. (see [#82](https://github.com/singerla/pptx-automizer/issues/82) and [#73](https://github.com/singerla/pptx-automizer/issues/73))
1041
-
-**No related chart worksheet**: It might happen to PowerPoint to lose the worksheet relation for a chart. If a chart gets corrupted by this, you will see a normal chart on your slide, but get an error message if you try to open the datasheet. Please replace the corrupted chart by a working one. (see [#104](https://github.com/singerla/pptx-automizer/issues/104))
1042
879
1043
-
If none of these could help, please don't hesitate to [talk about it](https://github.com/singerla/pptx-automizer/issues/new).
880
+
If none of these could help, please don't hesitate to [talk about it](https://github.com/singerla/pptx-automizer/issues/new).
0 commit comments