heavysixer / node-pptx

Generate PPTX files on the server-side with JavaScript.
MIT License
159 stars 44 forks source link

Extract presenter notes? #100

Open SeyyedKhandon opened 1 year ago

SeyyedKhandon commented 1 year ago

How can one extract just the presenter notes? The solution which I'm using is this:

// const fs = require("fs");
const PPTX2Json = require("pptx2json");
const pptx2json = new PPTX2Json();

pptx2json.toJson("./test.pptx").then((json) => {
  json = Object.keys(json)
    .filter((key) => key.includes("ppt/notesSlides/notesSlide"))
    .sort((a, b) => a - b)
    .map((key) =>
      json[key]["p:notes"]["p:cSld"][0]["p:spTree"][0]["p:sp"]
        .filter((item) => item["p:txBody"])
        .map((item) => item["p:txBody"][0]["a:p"])
        .map((item) => item.map((item) => item["a:r"]))[0]
        .filter((x) => x)
        .map((item) => [
          ...item.reduce((prev, curr) => [...prev, curr["a:t"]], []),
        ])
        .join(" ")
    );
  console.log(json);
  // fs.writeFileSync("./data.txt", JSON.stringify(json));
});