A JavaScript library for embedding fonts in PPTX files, with seamless integration support for pptxgenjs.
- 🎯 Font Embedding: Support for TTF, EOT, OTF and WOFF format font file embedding
- 🔌 pptxgenjs Integration: Seamless integration with pptxgenjs
- 📱 Cross-platform: Support for Node.js and browser environments
- 📦 TypeScript Support: Complete type definitions
npm install pptx-embed-fonts
# or
yarn add pptx-embed-fonts
# or
pnpm add pptx-embed-fontsimport PPTXEmbedFonts from "pptx-embed-fonts";
// Create instance
const embedFonts = new PPTXEmbedFonts();
// Load PPTX file
const pptxBuffer = await fetch("presentation.pptx").then((r) =>
r.arrayBuffer()
);
await embedFonts.load(pptxBuffer);
// Add font
const fontBuffer = await fetch("font.ttf").then((r) => r.arrayBuffer());
await embedFonts.addFontFromTTF("MyFont", fontBuffer);
const result = await embedFonts.save();import pptxgenjs from "pptxgenjs";
import { withPPTXEmbedFonts } from "pptx-embed-fonts/pptxgenjs";
// Create enhanced version of pptxgenjs
const EnhancedPPTXGenJS = withPPTXEmbedFonts(pptxgenjs);
const pptx = new EnhancedPPTXGenJS();
// Add font
const fontBuffer = await fetch("font.ttf").then((r) => r.arrayBuffer());
await pptx.addFont({
fontFace: "MyFont",
fontFile: fontBuffer,
fontType: "ttf",
});
// Create slide content
const slide = pptx.addSlide();
slide.addText("Hello World", {
fontFace: "MyFont",
fontSize: 24,
});
// Automatically embed fonts when exporting
const pptxFile = await pptx.writeFile({
fileName: "example.pptx",
});new PPTXEmbedFonts(zip?: JSZip)Load PPTX file buffer
Load JSZip instance
Add TTF format font
Add OTF format font
Add EOT format font
Add WOFF format font
Get font information
Update font-related configurations in PPTX file
Save and return the updated file
pptxgen: typeof pptxgenjs- pptxgenjs class
Enhanced version of pptxgenjs class with the following additional methods:
interface AddFontOptions {
fontFace: string;
fontFile: ArrayBuffer;
fontType: "ttf" | "eot" | "woff" | "otf";
}Get font information
- pptxgenjs - PowerPoint file generation library
- JSZip - File compression library
- opentype.js - Font parsing library