Skip to content

Commit 282b55d

Browse files
committed
chore(text): add new functions to readme
1 parent 4416a15 commit 282b55d

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

README.md

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const automizer = new Automizer({
187187

188188
// Remove all unused placeholders to prevent unwanted overlays:
189189
cleanupPlaceholders: false,
190-
190+
191191
// Use a customized version of pptxGenJs if required:
192192
// pptxGenJs: PptxGenJS,
193193
});
@@ -451,10 +451,64 @@ pres.addSlide('TextReplace.pptx', 1, (slide) => {
451451
});
452452
```
453453

454+
You can use `modify.setMultiText` to replace all text contents of an existing textfield by styled paragraphs, bulleted lists and text runs:
455+
456+
```ts
457+
import { modify } from 'pptx-automizer';
458+
459+
pres.addSlide('TextReplace.pptx', 1, (slide) => {
460+
slide.modifyElement(
461+
'setText',
462+
modify.setMultiText([
463+
{
464+
paragraph: {
465+
bullet: true,
466+
level: 0,
467+
marginLeft: 41338,
468+
indent: -87325,
469+
alignment: 'l',
470+
},
471+
textRuns: [
472+
{
473+
text: 'Bullet point level 0',
474+
style: {
475+
isItalics: true,
476+
color: {
477+
type: 'srgbClr',
478+
value: 'CCCCCC',
479+
},
480+
},
481+
},
482+
],
483+
},
484+
]),
485+
);
486+
});
487+
```
488+
489+
It is also possible to directly convert an HTML page into pptx text contents. HTML code will be flattened and converted into a MultiText array.
490+
491+
```ts
492+
import { modify } from 'pptx-automizer';
493+
494+
const html =
495+
'<html><body>' +
496+
'<ul>' +
497+
'<li><span style="font-size: 14px;">bullet 1 level 1</span></li>' +
498+
'</ul>' +
499+
'</body></html>';
500+
501+
pres.addSlide('TextReplace.pptx', 1, (slide) => {
502+
slide.modifyElement('setText', modify.htmlToMultiText(html));
503+
});
504+
```
505+
454506
Find out more about text replacement:
455507

456508
- [Replace and style by tags](https://github.com/singerla/pptx-automizer/blob/main/__tests__/replace-tagged-text.test.ts)
457509
- [Modify text elements using getAllTextElementIds](https://github.com/singerla/pptx-automizer/blob/main/__tests__/get-all-text-element-ids.test.ts)
510+
- [Replace text by multitext objects](https://github.com/singerla/pptx-automizer/blob/main/__tests__/replace-multi-text.test.ts)
511+
- [Replace text by HTML](https://github.com/singerla/pptx-automizer/blob/main/__tests__/replace-multi-text-html.test.ts)
458512

459513
## Modify Images
460514

@@ -586,6 +640,7 @@ pres.addSlide('charts', 2, (slide) => {
586640
This library wraps around the [PptxGenJS](https://github.com/gitbrent/PptxGenJS) to generate shapes from scratch. It is possible to use the `pptxGenJS` wrapper to generate shapes on a slide.
587641

588642
Here's an example of how to use `pptxGenJS` to add a text shape to a slide:
643+
589644
```ts
590645
pres.addSlide('empty', 1, (slide) => {
591646
// Use pptxgenjs to add text from scratch:
@@ -604,7 +659,6 @@ pres.addSlide('empty', 1, (slide) => {
604659
You can as well create charts with `pptxGenJS`:
605660

606661
```ts
607-
608662
const dataChartAreaLine = [
609663
{
610664
name: 'Actual Sales',
@@ -632,12 +686,12 @@ pres.addSlide('empty', 1, (slide) => {
632686
```
633687

634688
You can use the following functions to generate shapes with `pptxGenJS`:
635-
* addChart
636-
* addImage
637-
* addShape
638-
* addTable
639-
* addText
640689

690+
- addChart
691+
- addImage
692+
- addShape
693+
- addTable
694+
- addText
641695

642696
## Remove elements from a slide
643697

0 commit comments

Comments
 (0)