Skip to content

El modelo PptxData

Cuando llama a handler.load(buffer), obtiene un PptxData - el objeto raiz que contiene todas las diapositivas, temas, mascaras y metadatos.

Estructura de alto nivel

ts
interface PptxData {
	slides: PptxSlide[];
	slideMasters: PptxSlideMaster[];
	theme?: PptxTheme;
	themeColorMap: Record<string, string>;
	widthEmu: number; // ancho de diapositiva en EMU
	heightEmu: number; // altura de diapositiva en EMU
	metadata?: PptxMetadata;
}

PptxSlide

ts
interface PptxSlide {
	elements: PptxElement[];
	layoutPath?: string;
	background?: PptxBackground;
	notes?: string;
	hidden?: boolean;
	slideNumber?: number;
	name?: string;
}

La union PptxElement

PptxElement es una union discriminada en el campo type. Los 11 tipos de variantes son:

typeInterfazDescripcion
'text'TextPptxElementCuadros de texto, titulos, cuerpo
'image'ImagePptxElementImagenes raster y metarchivos EMF/WMF
'shape'ShapePptxElementFormas geometricas y conectores
'table'TablePptxElementTablas con filas/columnas
'chart'ChartPptxElementGraficos (23 tipos)
'group'GroupPptxElementGrupos que contienen otros elementos
'connector'ConnectorPptxElementConectores / lineas
'smartArt'SmartArtPptxElementDiagramas SmartArt
'media'MediaPptxElementAudio / video incrustado
'ink'InkPptxElementTinta digital
'ole'OlePptxElementObjetos OLE incrustados

Campos comunes

Todos los tipos de elementos comparten estos campos base:

ts
interface PptxElementBase {
	type: string;
	id: string;
	x: number; // posicion en pixeles aproximados
	y: number;
	width: number;
	height: number;
	rotation?: number;
	name?: string;
	hidden?: boolean;
}

Trabajar con elementos

Estreche siempre en type antes de acceder a campos especificos del variante:

ts
for (const element of slide.elements) {
	if (element.type === 'text') {
		console.log(element.text, element.fontFamily, element.fontSize);
	}
	if (element.type === 'group') {
		processElements(element.children);
	}
}

Lecturas relacionadas

Released under the Apache-2.0 License.