singerla / pptx-automizer

A template based pptx generator for Node.js
MIT License
68 stars 12 forks source link

Read files from memory instead of from a directory? #108

Closed mikemeerschaert closed 3 months ago

mikemeerschaert commented 4 months ago

I am trying to use this library in an AWS Lambda environment, so I don't have access to the file system. I'm generating a pptx file with PptxGenJs, then trying to add master slides from our corporate template that I'm reading in from s3. Is there a supported way to read a file from memory rather than a local directory?

i.e.

import pptxgen from "pptxgenjs"
import Automizer from "pptx-automizer"
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"

const pptx = new pptxgen()
//build presentation with pptxgen...

const s3Client = new S3Client()

const response = await s3Client.send(
  new GetObjectCommand({ Bucket: templateBucket, Key: templateKey })
)

const template = await response.Body?.transformToByteArray()

const myPresentation = await pptx.write({
    outputType: "nodebuffer"
})

const automizer = new Automizer()

const pres = automizer.loadRoot(template)
    .load(template, "template")
    .load(myPresentation, "myPres")

//...

I can see that .load and .loadRoot both only take a file path currently.