Skip to content

Commit 12049dd

Browse files
committed
chore(doc): add files from buffer/url to readme
1 parent d19397b commit 12049dd

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ If you require commercial support for complex .pptx automation, you can explore
2626
- [As a Package](#as-a-package)
2727
- [Usage](#usage)
2828
- [Basic Example](#basic-example)
29+
- [Load files from buffer/URL](#load-files-from-bufferurl)
2930
- [How to Select Slides Shapes](#how-to-select-slides-shapes)
3031
- [Select slide by number and shape by name](#select-slide-by-number-and-shape-by-name)
3132
- [Select slides by creationId](#select-slides-by-creationid)
@@ -226,6 +227,31 @@ const finalJSZip = await pres.getJSZip();
226227
const base64 = await finalJSZip.generateAsync({ type: 'base64' });
227228
```
228229

230+
## Load files from buffer/URL
231+
232+
It is possible to load `.pptx` files from buffer:
233+
234+
```ts
235+
const rootTemplate = await fs.readFile(
236+
`${__dirname}/pptx-templates/RootTemplate.pptx`,
237+
);
238+
const slideWithShapes = await fs.readFile(
239+
`${__dirname}/pptx-templates/SlideWithShapes.pptx`,
240+
);
241+
242+
// Additionally, you can fetch a template from url as well:
243+
const url =
244+
'https://raw.githubusercontent.com/singerla/pptx-automizer/main/__tests__/pptx-templates/SlideWithShapes.pptx';
245+
const response = await fetch(url);
246+
const buffer = await response.arrayBuffer();
247+
const bytes = new Uint8Array(buffer);
248+
249+
const pres = automizer
250+
.loadRoot(rootTemplate)
251+
.load(slideWithShapes, 'shapes')
252+
.load(bytes, 'shapesFromUrl');
253+
```
254+
229255
## How to Select Slides Shapes
230256

231257
`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.
@@ -783,7 +809,8 @@ To specify another slideLayout for an added output slide, you need to count slid
783809

784810
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).
785811

786-
If you require to modify slide master backgrounds, please refer to
812+
If you require to modify slide master backgrounds, please refer to
813+
787814
- [Modify master background color](https://github.com/singerla/pptx-automizer/blob/main/__tests__/modify-master-background-color.test.ts).
788815
- [Modify master background image](https://github.com/singerla/pptx-automizer/blob/main/__tests__/modify-master-background-image.test.ts).
789816

@@ -890,6 +917,7 @@ const setTextContent = function (label: number | string) {
890917
};
891918
};
892919
```
920+
893921
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.
894922

895923
You can use the modifier e.g. on adding an element:
@@ -931,10 +959,9 @@ If you encounter problems when opening a `.pptx`-file modified by this library,
931959
- **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.
932960
- **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).
933961
- **Replace Text not working**: 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))
934-
- **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))
935-
962+
- **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))
936963

937-
If none of these could help, please don't hesitate to [talk about it](https://github.com/singerla/pptx-automizer/issues/new).
964+
If none of these could help, please don't hesitate to [talk about it](https://github.com/singerla/pptx-automizer/issues/new).
938965

939966
## Testing
940967

0 commit comments

Comments
 (0)