### Expand ESLint Configuration with Type-Aware Rules (TypeScript) Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/example/README.md This configuration expands the ESLint setup to include type-aware lint rules for TypeScript files. It requires the 'tseslint' package and specifies project configuration files for type checking. This enhances code quality by catching type-related errors during linting. ```javascript export default tseslint.config([ globalIgnores(['dist']), { files: ['**/*.{ts,tsx}'], extends: [ // Other configs... // Remove tseslint.configs.recommended and replace with this ...tseslint.configs.recommendedTypeChecked, // Alternatively, use this for stricter rules ...tseslint.configs.strictTypeChecked, // Optionally, add this for stylistic rules ...tseslint.configs.stylisticTypeChecked, // Other configs... ], languageOptions: { parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, // other options... }, }, ]) ``` -------------------------------- ### Expand ESLint Configuration with React-Specific Rules (TypeScript) Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/example/README.md This configuration integrates ESLint with specific rules for React and React DOM using the 'eslint-plugin-react-x' and 'eslint-plugin-react-dom' packages. It requires these plugins to be installed and configured within the ESLint setup, alongside project configuration for type checking. ```javascript // eslint.config.js import reactX from 'eslint-plugin-react-x' import reactDom from 'eslint-plugin-react-dom' export default tseslint.config([ globalIgnores(['dist']), { files: ['**/*.{ts,tsx}'], extends: [ // Other configs... // Enable lint rules for React reactX.configs['recommended-typescript'], // Enable lint rules for React DOM reactDom.configs.recommended, ], languageOptions: { parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, // other options... }, }, ]) ``` -------------------------------- ### Install pptx-embed-fonts using npm, yarn, or pnpm Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/README.md This code snippet demonstrates how to install the 'pptx-embed-fonts' library using different package managers. It covers npm, yarn, and pnpm, ensuring compatibility with various project setups. ```bash npm install pptx-embed-fonts # or yarn add pptx-embed-fonts # or pnpm add pptx-embed-fonts ``` -------------------------------- ### PPTXEmbedFonts Class: Load PPTX from Buffer Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Shows how to load a PPTX file into the PPTXEmbedFonts class using an ArrayBuffer. This example covers both browser (using fetch) and Node.js (using fs) environments. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; import fs from "fs"; async function loadPPTX() { const embedFonts = new PPTXEmbedFonts(); // Browser: Load from fetch const browserBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(browserBuffer); // Node.js: Load from file system const nodeBuffer = fs.readFileSync("presentation.pptx"); const arrayBuffer = new Uint8Array(nodeBuffer).buffer; await embedFonts.load(arrayBuffer); } ``` -------------------------------- ### Basic Usage of PPTXEmbedFonts in TypeScript Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/README.md This TypeScript example shows the basic usage of the 'PPTXEmbedFonts' class. It covers loading a PPTX file from a buffer, adding a TTF font, and saving the modified PPTX file. Dependencies include 'fetch' API for loading files. ```typescript import 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(); ``` -------------------------------- ### PPTXEmbedFonts Class: Embed Fonts in Existing PPTX Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Demonstrates how to use the PPTXEmbedFonts class to load an existing PPTX file, embed a TTF font, and save the modified presentation. This example is suitable for browser environments using fetch. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; async function embedFontsInExistingPPTX() { // Create a new instance const embedFonts = new PPTXEmbedFonts(); // Load an existing PPTX file const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); // Add a TTF font const fontBuffer = await fetch("custom-font.ttf").then((r) => r.arrayBuffer()); await embedFonts.addFontFromTTF("CustomFont", fontBuffer); // Save the modified PPTX with embedded fonts const result = await embedFonts.save(); // In browser: create download link const blob = new Blob([result], { type: "application/vnd.openxmlformats-officedocument.presentationml.presentation" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "presentation-with-fonts.pptx"; a.click(); } ``` -------------------------------- ### Get Font Information using opentype.js Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Retrieves metadata and information from a font file using opentype.js. This is useful for extracting the correct font family name needed for embedding. Requires the pptx-embed-fonts library. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; async function inspectFont() { const embedFonts = new PPTXEmbedFonts(); const fontBuffer = await fetch("unknown-font.ttf").then((r) => r.arrayBuffer()); const fontInfo = embedFonts.getFontInfo(fontBuffer); // Extract font family name (handles both English and localized names) const fontFace = fontInfo.names.fontFamily.en || fontInfo.names.fontFamily.zh; console.log("Font Family:", fontFace); console.log("Full Name:", fontInfo.names.fullName); console.log("Version:", fontInfo.names.version); console.log("Number of glyphs:", fontInfo.numGlyphs); console.log("Units per Em:", fontInfo.unitsPerEm); // Now use the correct font name when embedding const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); await embedFonts.addFontFromTTF(fontFace, fontBuffer); const result = await embedFonts.save(); } ``` -------------------------------- ### Embed Custom TTF Font in Node.js pptxgenjs Presentation Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Provides a complete Node.js example for embedding a custom TTF font into a presentation. It reads the font file from the file system using `fs.readFileSync`, extracts font information using `pptx.getFontInfo()`, adds the font using `pptx.addFont()`, and then creates slides with text styled using the embedded font. The final presentation is saved to the 'output' directory. ```typescript import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; import pptxgenjs from "pptxgenjs"; import { withPPTXEmbedFonts } from "pptx-embed-fonts/pptxgenjs"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); async function createNodePresentation() { const EnhancedPPTXGenJS = withPPTXEmbedFonts(pptxgenjs); const pptx = new EnhancedPPTXGenJS(); // Read font from file system const fontPath = path.join(__dirname, "fonts", "custom-font.ttf"); const fontFile = fs.readFileSync(fontPath); const arrayBuffer = new Uint8Array(fontFile).buffer; // Get font info to extract proper name const fontInfo = pptx.getFontInfo(arrayBuffer); const fontFace = fontInfo.names.fontFamily.en || fontInfo.names.fontFamily.zh; // Add font await pptx.addFont({ fontFace: fontFace, fontFile: arrayBuffer, fontType: "ttf", }); // Create presentation content const slide = pptx.addSlide(); slide.addText("Custom Font Presentation", { x: 0, y: 0, w: "100%", h: 1, align: "center", fontSize: 32, fontFace: fontFace, bold: true, }); slide.addText("This text uses an embedded custom font that will display correctly on any system.", { x: 0.5, y: 2, w: 9, h: 1, fontSize: 18, fontFace: fontFace, }); // Write to file await pptx.writeFile({ fileName: path.join(__dirname, "output", "presentation.pptx"), }); console.log("Presentation created successfully!"); } createNodePresentation().catch(console.error); ``` -------------------------------- ### Integrate pptx-embed-fonts with pptxgenjs in TypeScript Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/README.md This TypeScript example demonstrates integrating 'pptx-embed-fonts' with 'pptxgenjs'. It uses the 'withPPTXEmbedFonts' higher-order function to enhance the 'pptxgenjs' class, allowing for font addition and embedding during PPTX generation. Requires 'pptxgenjs' and 'pptx-embed-fonts'. ```typescript 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", }); ``` -------------------------------- ### PPTXEmbedFonts Class: Load from JSZip Instance Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Demonstrates loading a PPTX file into PPTXEmbedFonts using an existing JSZip instance. This is useful when the PPTX is already unzipped or when more control over zip processing is needed. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; import JSZip from "jszip"; async function loadFromJSZip() { const embedFonts = new PPTXEmbedFonts(); // Create and load JSZip instance manually const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); const zip = new JSZip(); await zip.loadAsync(pptxBuffer); // Load the zip into PPTXEmbedFonts await embedFonts.loadZip(zip); // Now you can add fonts and save const fontBuffer = await fetch("font.ttf").then((r) => r.arrayBuffer()); await embedFonts.addFontFromTTF("MyFont", fontBuffer); const result = await embedFonts.save(); } ``` -------------------------------- ### Add Multiple Font Types to pptxgenjs Presentation Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Demonstrates adding various font types (TTF, OTF, WOFF, EOT) to a pptxgenjs presentation using the `withPPTXEmbedFonts` wrapper. This function fetches font files from a URL, adds them using `pptx.addFont()`, and then creates slides with text styled using these embedded fonts. The presentation is saved as 'multi-font-presentation.pptx'. ```typescript import pptxgenjs from "pptxgenjs"; import { withPPTXEmbedFonts } from "pptx-embed-fonts/pptxgenjs"; async function addMultipleFonts() { const EnhancedPPTXGenJS = withPPTXEmbedFonts(pptxgenjs); const pptx = new EnhancedPPTXGenJS(); // Add TTF font const ttfFont = await fetch("Roboto.ttf").then((r) => r.arrayBuffer()); await pptx.addFont({ fontFace: "Roboto", fontFile: ttfFont, fontType: "ttf", }); // Add OTF font const otfFont = await fetch("OpenSans.otf").then((r) => r.arrayBuffer()); await pptx.addFont({ fontFace: "Open Sans", fontFile: otfFont, fontType: "otf", }); // Add WOFF font const woffFont = await fetch("Inter.woff").then((r) => r.arrayBuffer()); await pptx.addFont({ fontFace: "Inter", fontFile: woffFont, fontType: "woff", }); // Add EOT font const eotFont = await fetch("Custom.eot").then((r) => r.arrayBuffer()); await pptx.addFont({ fontFace: "Custom", fontFile: eotFont, fontType: "eot", }); // Create slides using the fonts const slide = pptx.addSlide(); slide.addText("Roboto Text", { fontFace: "Roboto", fontSize: 24, x: 0.5, y: 0.5 }); slide.addText("Open Sans Text", { fontFace: "Open Sans", fontSize: 24, x: 0.5, y: 1.5 }); slide.addText("Inter Text", { fontFace: "Inter", fontSize: 24, x: 0.5, y: 2.5 }); slide.addText("Custom Text", { fontFace: "Custom", fontSize: 24, x: 0.5, y: 3.5 }); await pptx.writeFile({ fileName: "multi-font-presentation.pptx" }); } ``` -------------------------------- ### PPTXEmbedFonts Class Constructor in TypeScript Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/README.md This TypeScript code defines the constructor for the 'PPTXEmbedFonts' class. It optionally accepts a 'JSZip' instance, allowing for pre-loaded zip archives. This is useful for advanced manipulation of PPTX files. ```typescript new PPTXEmbedFonts(zip?: JSZip) ``` -------------------------------- ### PPTXEmbedFonts Class: Add OTF Font Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Details the process of embedding an OpenType Font (OTF) file into a PPTX presentation using the addFontFromOTF method. The library handles the internal conversion of OTF fonts to the required format. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; async function addOTFFont() { const embedFonts = new PPTXEmbedFonts(); const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); // Load OTF font file const otfBuffer = await fetch("OpenSans-Regular.otf").then((r) => r.arrayBuffer()); await embedFonts.addFontFromOTF("Open Sans", otfBuffer); const result = await embedFonts.save(); } ``` -------------------------------- ### PPTXEmbedFonts Class: Add TTF Font Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Explains how to embed a TrueType Font (TTF) file into a PPTX presentation using the addFontFromTTF method. The fontName parameter must exactly match the font face name used within the presentation slides. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; async function addTTFFont() { const embedFonts = new PPTXEmbedFonts(); const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); // Load TTF font file const ttfBuffer = await fetch("Roboto-Regular.ttf").then((r) => r.arrayBuffer()); // Add font with the exact name used in the presentation await embedFonts.addFontFromTTF("Roboto", ttfBuffer); // Add multiple fonts const boldFont = await fetch("Roboto-Bold.ttf").then((r) => r.arrayBuffer()); await embedFonts.addFontFromTTF("Roboto Bold", boldFont); const result = await embedFonts.save(); } ``` -------------------------------- ### Embed WOFF Font into PPTX Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Embeds a Web Open Font Format (WOFF) file into the presentation. WOFF fonts are decompressed and converted internally. Requires the pptx-embed-fonts library. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; async function addWOFFFont() { const embedFonts = new PPTXEmbedFonts(); const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); // Load WOFF font file (commonly used in web) const woffBuffer = await fetch("Inter-Regular.woff").then((r) => r.arrayBuffer()); await embedFonts.addFontFromWOFF("Inter", woffBuffer); const result = await embedFonts.save(); } ``` -------------------------------- ### Enhance pptxgenjs with Font Embedding Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt A higher-order function that enhances the pptxgenjs library with font embedding capabilities. It returns an enhanced class that can be used to create new presentations with embedded fonts. Requires pptxgenjs and pptx-embed-fonts. ```typescript import pptxgenjs from "pptxgenjs"; import { withPPTXEmbedFonts } from "pptx-embed-fonts/pptxgenjs"; async function createPresentationWithFonts() { // Create enhanced pptxgenjs class const EnhancedPPTXGenJS = withPPTXEmbedFonts(pptxgenjs); const pptx = new EnhancedPPTXGenJS(); // Load and add custom font const fontFile = await fetch("/font.ttf").then((res) => res.arrayBuffer()); const fontInfo = pptx.getFontInfo(fontFile); const fontFace = fontInfo.names.fontFamily.en || fontInfo.names.fontFamily.zh; await pptx.addFont({ fontFace: fontFace, fontType: "ttf", fontFile: fontFile, }); // Create slide with custom font const slide = pptx.addSlide(); slide.addText("Hello World", { x: 0, y: 1, w: "100%", h: 2, align: "center", color: "0088CC", fontSize: 24, fontFace: fontFace, }); // Write file - fonts are automatically embedded await pptx.writeFile({ fileName: "presentation.pptx", }); } ``` -------------------------------- ### Embed EOT Font into PPTX Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Embeds an Embedded OpenType (EOT) font file into the presentation. EOT is the native format used by PowerPoint for embedded fonts. Requires the pptx-embed-fonts library. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; async function addEOTFont() { const embedFonts = new PPTXEmbedFonts(); const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); // Load EOT font file (native PowerPoint format) const eotBuffer = await fetch("Arial-Custom.eot").then((r) => r.arrayBuffer()); await embedFonts.addFontFromEOT("Arial Custom", eotBuffer); const result = await embedFonts.save(); } ``` -------------------------------- ### PPTXEmbedFonts Class Methods for Font Management in TypeScript Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/README.md This TypeScript code outlines the core methods of the 'PPTXEmbedFonts' class for loading, adding, and saving PPTX files with embedded fonts. It supports loading from ArrayBuffer or JSZip instances and adding various font formats (TTF, OTF, EOT, WOFF). ```typescript load(fileBuffer: ArrayBuffer): Promise loadZip(zip: JSZip): Promise addFontFromTTF(fontName: string, ttfFile: ArrayBuffer): Promise addFontFromOTF(fontName: string, otfFile: ArrayBuffer): Promise addFontFromEOT(fontName: string, eotFile: ArrayBuffer): Promise addFontFromWOFF(fontName: string, woffFile: ArrayBuffer): Promise getFontInfo(fontBuffer: ArrayBuffer): any updateFiles(): Promise save(): Promise ``` -------------------------------- ### withPPTXEmbedFonts Function Options Interface in TypeScript Source: https://github.com/liyao1520/pptx-embed-fonts/blob/main/README.md This TypeScript code defines the interface for the options object used by the 'addFont' method when integrating 'pptx-embed-fonts' with 'pptxgenjs'. It specifies the required properties: fontFace, fontFile, and fontType. ```typescript interface AddFontOptions { fontFace: string; fontFile: ArrayBuffer; fontType: "ttf" | "eot" | "woff" | "otf"; } ``` -------------------------------- ### Save Modified PPTX with Embedded Fonts Source: https://context7.com/liyao1520/pptx-embed-fonts/llms.txt Saves the modified PPTX file with all embedded fonts. The function returns an ArrayBuffer in browser environments and a Buffer in Node.js environments. Requires the pptx-embed-fonts library. ```typescript import PPTXEmbedFonts from "pptx-embed-fonts"; import fs from "fs"; async function savePPTX() { const embedFonts = new PPTXEmbedFonts(); const pptxBuffer = await fetch("presentation.pptx").then((r) => r.arrayBuffer()); await embedFonts.load(pptxBuffer); const fontBuffer = await fetch("font.ttf").then((r) => r.arrayBuffer()); await embedFonts.addFontFromTTF("CustomFont", fontBuffer); // Save returns ArrayBuffer (browser) or Buffer (Node.js) const result = await embedFonts.save(); // Node.js: Write to file fs.writeFileSync("output.pptx", Buffer.from(result as ArrayBuffer)); // Browser: Trigger download const blob = new Blob([result], { type: "application/vnd.openxmlformats-officedocument.presentationml.presentation" }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = "output.pptx"; link.click(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.