@ diceui/ pptx 核心
一个PPTX引擎,用于在浏览器中解析,渲染,编辑并保存PowerPoint演示文稿.
文档
访问 pptx.diceui.com (中文(简体) ) 查看文件全文.
安装
npm install @diceui/pptx-core
放映幻灯片
import { buildPresentation, readPptx, renderSlide } from "@diceui/pptx-core";
const files = await readPptx(arrayBuffer);
const presentation = buildPresentation(files);
const handle = renderSlide(presentation, presentation.slides[0]);
document.body.appendChild(handle.element);
// When done
handle.dispose();
完整浏览器
PptxViewer 在框外提供导航、缩放、缩略图和文本搜索:
import { PptxViewer } from "@diceui/pptx-core";
const viewer = new PptxViewer(container);
await viewer.open(arrayBuffer);
await viewer.goToSlide(2);
编辑并保存
装入 keepSourcePackage: true 以保留源归档,然后应用已键入的编辑操作并写回 a .pptx (动画、评论、供应商延伸):
import { applyEdit, buildPresentation, readPptx, writePptx } from "@diceui/pptx-core";
const presentation = buildPresentation(await readPptx(buffer, { keepSourcePackage: true }));
const result = await applyEdit(presentation, {
type: "setTextRun",
slideId: presentation.slides[0].id,
nodeId: "2",
paragraphIndex: 0,
runIndex: 0,
text: "Hello",
});
// result.undo() restores the previous state
const bytes = await writePptx(presentation);
支助行动:
- 文本 :
setTextRun, (中文(简体) ),setTextBody, (中文(简体) ),setTextStyle,以及setParagraphStyle - 形状 :
setNodeTransform, (中文(简体) ),setSolidFill, (中文(简体) ),setOutline, (中文(简体) ),deleteNode, (中文(简体) ),duplicateNode, (中文(简体) ),reorderNode, (中文(简体) ),addTextBox, (中文(简体) ),addShape, (中文(简体) ),addImage,以及pasteNodes(与copyNodes()(中文(简体) ) - 幻灯片 :
addSlide, (中文(简体) ),moveSlide, (中文(简体) ),duplicateSlide, (中文(简体) ),deleteSlide,以及setSlideBackground batch: 多个操作作为可撤销的步骤
创建幻灯片或形状的编辑器报告其编号 result.createdSlideId 财务报告和审定财务报表 result.createdNodeIds对于拾取者, getPresentationFonts() 列出甲板的字体和 getPresetShapePath() 绘制预设形状为 SVG 路径数据 .
嵌入式字体
字体解码(包括 MTX 压缩的嵌入式字体) 生活在一个单独的切入点,所以它不包含在您的捆绑中, 除非使用 :
import { decodeEmbeddedFont } from "@diceui/pptx-core/fonts";
OOXML 支持
见 OXML-SUPPORT.md (英语) 对ECMA-376的特征矩阵.
许可证
阿帕奇2.0 (英语). 第三方项目产生的部分;见 通知下的文件 LICENSES/ 持有各自的许可证(预定义的表格样式为MPL-2.0).