PPTX

幻灯片布局

配置幻灯片尺寸、背景和演讲者备注

控制每张幻灯片的尺寸、背景和备注。

幻灯片尺寸

Presentation 上设置自定义宽度和高度:

import { Presentation, Slide, Shape } from "@office-open/pptx";

const pres = new Presentation({
    slideWidth: 13.33, // 宽度(英寸)
    slideHeight: 7.5, // 高度(英寸)
    slides: [
        new Slide({
            children: [new Shape({ x: 1, y: 1, width: 11, height: 5, text: "Widescreen content" })],
        }),
    ],
});

幻灯片尺寸预设

使用 SlideSizePreset 获取标准尺寸:

import { Presentation, SlideSizePreset } from "@office-open/pptx";

const pres = new Presentation({
    slideWidth: SlideSizePreset.WIDESCREEN_16_9, // 13.33 x 7.5 英寸
    // slideWidth: SlideSizePreset.STANDARD_4_3,     // 10 x 7.5 英寸
    // slideWidth: SlideSizePreset.A3_PORTRAIT,      // 11.69 x 16.54 英寸
    // slideWidth: SlideSizePreset.A4_LANDSCAPE,     // 11.69 x 8.27 英寸
    slides: [],
});

常用预设

预设尺寸(英寸)宽高比
WIDESCREEN_16_913.33 x 7.516:9
STANDARD_4_310 x 7.54:3
A3_PORTRAIT11.69 x 16.54A3 纵向
A3_LANDSCAPE16.54 x 11.69A3 横向
A4_PORTRAIT8.27 x 11.69A4 纵向
A4_LANDSCAPE11.69 x 8.27A4 横向
LETTER_PORTRAIT8.5 x 11US Letter 纵向
LETTER_LANDSCAPE11 x 8.5US Letter 横向
BANNER13.33 x 3.75横幅

幻灯片背景

纯色

new Slide({
    background: { type: "solid", color: "1F4E79" },
    children: [],
});

渐变

new Slide({
    background: {
        type: "gradient",
        stops: [
            { position: 0, color: "0D47A1" },
            { position: 100, color: "1976D2" },
        ],
        angle: 90,
    },
    children: [],
});

图片背景

import fs from "node:fs";

new Slide({
    background: {
        type: "image",
        data: fs.readFileSync("bg.png"),
        imageType: "png",
    },
    children: [],
});

演讲者备注

添加在演示者模式下可见的备注:

new Slide({
    children: [new Shape({ x: 1, y: 1, width: 8, height: 5, text: "Slide content" })],
    notes: "Remember to emphasize the key metrics in this slide. Pause for questions after showing the chart.",
});

演示文稿元数据

const pres = new Presentation({
    title: "Annual Report 2025",
    creator: "John Doe",
    company: "Acme Inc.",
    description: "Yearly financial summary",
    subject: "Finance",
    keywords: "annual, report, finance",
    slides: [],
});

单位转换辅助函数

import { convertPixelsToEmu, convertEmuToPixels, percentToTHousandths } from "@office-open/pptx";

convertPixelsToEmu(800); // 像素转 EMU
convertEmuToPixels(914400); // EMU 转像素
percentToTHousandths(75); // 75% → 750000(千分比)
Copyright © 2026