pymupdf-node
PyMuPDF for Node JS
Getting Started
Install node modules
npm install
Trying
Import into your source code with:
import * as PyMuPDFNode from "pymupdf-node";
Wheels should be loaded into the pymupdf module with:
const pymupdf = await PyMuPDFNode.loadPyMuPDF("node_modules/pymupdf-node/pymupdf/pymupdf-1.26.0-cp312-abi3-pyodide_2024_0_wasm32.whl");
And if you need PyMuPDF4LLM, with:
const pymupdf4LLM = await PyMuPDFNode.loadPyMuPDF4LLM("node_modules/pymupdf-node/pymupdf/pymupdf4llm-0.0.24-py3-none-any.whl");
Open a document:
let doc = pymupdf.open("test.pdf");
Copy a page:
doc.copy_page(0);
Get document as markdown:
const md = pymupdf4LLM.to_markdown(doc, {
page_chunks: false,
write_images: false,
ignore_images: true,
image_path: "",
extract_words: false,
show_progress: false,
});
console.log(md);
Full example:
import * as PyMuPDFNode from "pymupdf-node";
const pymupdf = await PyMuPDFNode.loadPyMuPDF("node_modules/pymupdf-node/pymupdf/pymupdf-1.26.0-cp312-abi3-pyodide_2024_0_wasm32.whl");
const pymupdf4LLM = await PyMuPDFNode.loadPyMuPDF4LLM("node_modules/pymupdf-node/pymupdf/pymupdf4llm-0.0.24-py3-none-any.whl");
let doc = pymupdf.open("test.pdf");
doc.copy_page(0);
const md = pymupdf4LLM.to_markdown(doc, {
page_chunks: false,
write_images: false,
ignore_images: true,
image_path: "",
extract_words: false,
show_progress: false,
});
console.log(md);
Documentation
PyMuPDF Node is PyMuPDF for JavaScript environments, but just use the PyMuPDF Python API as if it was JavaScript, see the PyMuPDF API documentation.