emf-to-png
v0.1.0
Published
WASM-based EMF to PNG/JPEG converter for Node.js. No Office, LibreOffice, or Inkscape required.
Maintainers
Readme
emf-to-png
Convert EMF files to PNG or JPEG in Node.js without Office, LibreOffice, or Inkscape.
This package is built for the common DOCX extraction case where images appear as
.emf files and need to be rendered on a server or in a Node.js pipeline.
Status
EMF support is working for classic EMF files through a bundled WebAssembly build
of libemf2svg, followed by rasterization with @resvg/resvg-js.
WMF and EMF+ are not part of the current stable API yet. Some advanced or application-specific EMF records may still fail depending on upstream renderer coverage.
Install
npm install emf-to-pngUsage
import { convert, convertFile } from "emf-to-png";
import { readFile } from "node:fs/promises";
await convertFile("diagram.emf", "diagram.png", { width: 1200 });
const input = await readFile("diagram.emf");
const png = await convert(input, {
width: 1200,
background: "#ffffff",
format: "png",
});CLI
npx emf-to-png input.emf output.pngEnvironment options:
EMF_PNG_WIDTH=1200
EMF_PNG_HEIGHT=800
EMF_PNG_DPI=96
EMF_PNG_BG=#ffffff
EMF_PNG_FORMAT=pngAPI
convert(input: Buffer | Uint8Array, options?: ConvertOptions): Promise<Buffer>
convertFile(inputPath: string, outputPath?: string, options?: ConvertOptions): Promise<string>
emfOrWmfToSvg(kind: "emf", data: Uint8Array, dpi?: number): Promise<string>ConvertOptions:
interface ConvertOptions {
width?: number;
height?: number;
background?: string;
dpi?: number;
format?: "png" | "jpeg";
fallback?: boolean;
logger?: (message: string) => void;
}By default, conversion errors throw. Set fallback: true if you prefer a
placeholder PNG instead.
Development
Build the EMF WebAssembly renderer with Docker:
npm run build:wasmBuild the JavaScript package:
npm run build:js
node scripts/postbuild-copy-wasm.mjsRun tests:
npm testFull build:
npm run build