JunfengRan/PPTWork / ppt
ppt
UnverifiedBuild PPT / PowerPoint / 演示文稿 / slide decks end-to-end via a .pptwork/<deck>/ filesystem contract. Use when the user wants to plan, author, screenshot, or export a slide deck. Provides Node scripts for deck CRUD, headless screenshot, and editable PPTX export. Covers clarification, story planning, single-page authoring (via the ppt-html-authoring skill), visual QC, and export troubleshooting.
scripts/export.mjs
View on GitHub#!/usr/bin/env node
// Export a deck's slides into a single .pptx file.
//
// Two modes:
//
// --mode=editable (DEFAULT for new decks)
// Uses html2pptx-pro to convert slide HTML into editable PowerPoint
// elements. This is the main export path when the recipient needs to
// revise text/shapes in PowerPoint. It is still an HTML-to-PPTX
// conversion, so verify the output; use raster when visual fidelity is
// more important than editability.
//
// --mode=raster
// Each slide is captured as a single full-page PNG and placed onto
// a 13.333 x 7.5 inch slide. Pixel-faithful to the browser preview;
// text is not selectable but **what you see is what you get**.
//
// --editable-engine=dom-to-pptx
// Backup editable engine. It is generally less reliable and currently
// intended only for one-slide diagnostics.
//
// Usage:
// node export.mjs <deck-name> [--mode raster|editable] [--output <path>]
// [--dpi N] [--keep-cache]
import fs from "node:fs/promises";
import path from "node:path";
import { createRequire } from "node:module";
import {
readDeck,
deckExists,
getDeckPath,
getSlidePath,
} from "./lib/deck.mjs";
import {
renderSlideToPng,
renderDeckWithHtml2PptxPro,
renderSlideWithDomToPptx,
} from "./lib/render.mjs";
const require = createRequire(import.meta.url);
const directory = process.cwd();
function out(...lines) {
process.stdout.write(lines.flat().join("\n") + "\n");
}
function fail(...lines) {
process.stdout.write(lines.flat().join("\n") + "\n");
process.exit(1);
}
function parseArgs(argv) {
const positional = [];
const flags = {};
for (let i = 0; i < argv.length; i++) {
const a = argv[i];
if (a.startsWith("--")) {
const key = a.slice(2);
const next = argv[i + 1];
if (next !== undefined && !next.startsWith("--")) {
flags[key] = next;
i++;
} else {
flags[key] = true;
}
} else {
positional.push(a);
}
}
return { positional, flags };
}
function loadPptxgen() {
try {
return require("pptxgenjs");
} catch (e) {
fail(
`[Error] pptxgenjs not installed: ${e?.message || e}`,
`[Hint] Run \`npm install\` (or \`bun install\`) inside skills/ppt first.`,
);
}
}
// Speaker notes are stored inside a single self-contained slide.html node.
// Extracted with a regex (avoids spinning up another headless browser just to
// read a JSON island).
async function extractSpeakerNotes(htmlPath) {
let html;
try {
html = await fs.readFile(htmlPath, "utf-8");
} catch {
return undefined;
}
const m = html.match(
/<script[^>]*id=["']ppt-speaker-notes-json["'][^>]*>([\s\S]*?)<\/script>/i,
);
if (!m) return undefined;
const raw = m[1].trim();
if (!raw) return undefined;
try {
const parsed = JSON.parse(raw);
if (typeof parsed === "string") return parsed;
if (parsed && typeof parsed.text === "string") return parsed.text;
if (parsed && typeof parsed.content === "string") return parsed.content;
return raw;
} catch {
return raw;
}
}
async function exportRaster({ deck, deckName, outputPath, flags }) {
const Pptxgen = loadPptxgen();
const pres = new Pptxgen();
pres.layout = "LAYOUT_WIDE";
pres.author = flags.author || "PPT Skill";
pres.company = flags.company || "PPT Skill";
pres.subject = flags.subject || "Generated by ppt skill";
pres.title = flags.title || deckName;
const layoutW = pres.presLayout?.width ? pres.presLayout.width / 914400 : 13.333;
const layoutH = pres.presLayout?.height ? pres.presLayout.height / 914400 : 7.5;
for (let i = 0; i < deck.slides.length; i++) {
const slideName = deck.slides[i];
const htmlPath = path.join(getSlidePath(directory, deckName, slideName), "slide.html");
process.stderr.write(`[ppt] rasterizing slide ${i + 1}/${deck.slides.length}: ${slideName}\n`);
const { png } = await renderSlideToPng(htmlPath, { deviceScaleFactor: 2 });
const dataUrl = `data:image/png;base64,${png.toString("base64")}`;
const slide = pres.addSlide();
slide.background = { color: "FFFFFF" };
slide.addImage({
data: dataUrl,
x: 0,
y: 0,
w: layoutW,
h: layoutH,
});
const notes = await extractSpeakerNotes(htmlPath);
if (notes) slide.addNotes(notes);
}
await pres.writeFile({ fileName: outputPath });
}
async function exportEditable({ deck, deckName, outputPath, flags }) {
const htmlPaths = deck.slides.map((slideName) =>
path.join(getSlidePath(directory, deckName, slideName), "slide.html"),
);
const engine = flags["editable-engine"] || "html2pptx-pro";
if (engine === "dom-to-pptx") {
if (htmlPaths.length !== 1) {
fail(
`[Error] dom-to-pptx backup currently supports one slide per export.`,
`[Hint] Use the default html2pptx-pro editable export, or use --mode raster for high-fidelity full decks.`,
);
}
await renderSlideWithDomToPptx(htmlPaths[0], outputPath, { selector: ".slide" });
return { warnings: ["dom-to-pptx is a backup engine and may have layout drift"] };
}
if (engine !== "html2pptx-pro") {
fail(
`[Error] Unknown editable engine: ${engine}`,
`[Hint] Expected html2pptx-pro (default) or dom-to-pptx.`,
);
}
await renderDeckWithHtml2PptxPro(htmlPaths, outputPath, { selector: ".slide" });
return { warnings: [] };
}
async function main() {
const { positional, flags } = parseArgs(process.argv.slice(2));
const deckName = positional[0];
if (!deckName) fail("[Error] usage: export.mjs <deck-name> [--mode editable|raster] [--output <path>]");
if (!(await deckExists(directory, deckName))) {
fail(
`[Error] Deck "${deckName}" does not exist.`,
`[State] No deck found at .pptwork/${deckName}/`,
);
}
const deck = await readDeck(directory, deckName);
const mode =
flags.mode === "editable" || flags.mode === "raster"
? flags.mode
: deck.exportMode === "editable"
? "editable"
: "editable";
if (deck.slides.length === 0) {
fail(
`[Error] Deck "${deckName}" has 0 slides.`,
`[Hint] Use \`deck.mjs init-slide ${deckName} <slide>\` to add slides first.`,
);
}
const outputPath = flags.output
? path.isAbsolute(flags.output)
? flags.output
: path.resolve(directory, flags.output)
: path.join(getDeckPath(directory, deckName), `${deckName}.pptx`);
await fs.mkdir(path.dirname(outputPath), { recursive: true });
for (const slideName of deck.slides) {
const htmlPath = path.join(getSlidePath(directory, deckName, slideName), "slide.html");
try {
await fs.access(htmlPath);
} catch {
fail(
`[Error] Missing slide.html for slide "${slideName}".`,
`[State] Expected at ${path.relative(directory, htmlPath)}`,
`[Hint] Author all slides before exporting.`,
);
}
}
let report = null;
if (mode === "editable") {
report = await exportEditable({ deck, deckName, outputPath, flags });
} else {
await exportRaster({ deck, deckName, outputPath, flags });
}
const stat = await fs.stat(outputPath);
const lines = [
`[Done] Exported ${deck.slides.length} slide(s) to ${path.relative(directory, outputPath)}`,
`[Mode] ${mode}` +
(mode === "editable"
? " (html2pptx-pro editable output; verify layout and use raster if fidelity matters)"
: " (full-page PNG per slide, 16:9 LAYOUT_WIDE)"),
`[Bytes] ${stat.size}`,
];
if (report) {
if (report.warnings.length) {
lines.push("[Warnings]");
for (const w of report.warnings) lines.push(" " + w);
}
}
lines.push(
"",
mode === "raster"
? `[Next] Raster is the high-fidelity fallback: text is not editable, but browser visuals are preserved.`
: `[Next] Editable is the main path, but still verify in PowerPoint. If anything renders wrong (font drift, overlapping shapes, layout shift), re-run with \`--mode raster\`; for diagnostics only, try \`--editable-engine dom-to-pptx\` on a single-slide deck.`,
);
out(lines);
}
main().catch((e) => {
fail(`[Error] export failed: ${e?.stack || e?.message || String(e)}`);
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |