Skip to content

Basic usage ​

Node 20+ ​

ts
import { toMarkdown } from "@nalinor/mupdf4llm";
import { readFileSync, writeFileSync } from "node:fs";

const pdf = readFileSync("report.pdf");
const md = await toMarkdown(pdf);
writeFileSync("report.md", md);

Bun ​

ts
import { toMarkdown } from "@nalinor/mupdf4llm";

const pdf = await Bun.file("report.pdf").bytes();
await Bun.write("report.md", await toMarkdown(pdf));

Browser ​

ts
import { toMarkdown } from "@nalinor/mupdf4llm";

const res = await fetch("/report.pdf");
const buf = await res.arrayBuffer();
console.log(await toMarkdown(buf));

With options ​

ts
await toMarkdown(pdf, {
  pages: [0, 1, 2, 3, 4], // first five only
  margins: [36, 36, 36, 36], // crop 0.5" margin all around
  tableStrategy: "lines",
  pageSeparators: true,
});

From a URL pipeline ​

ts
async function pdfToMd(url: string): Promise<string> {
  const buf = await fetch(url).then((r) => r.arrayBuffer());
  return await toMarkdown(buf);
}

AGPL-3.0-or-later — inherited from PyMuPDF and pymupdf4llm.