From 13f5950389446a45932d6fff5ed141c1909ea3a1 Mon Sep 17 00:00:00 2001 From: "sergey.flakon" Date: Mon, 6 Jul 2026 15:45:14 -0400 Subject: [PATCH] Add PDF -> XLSX conversion support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `mpx convert input.pdf output.xlsx` now works. xlsx is a supported v3/pdf conversion output (extracts tabular content, one worksheet per detected table). The PDF path downloads v3/pdf/{id}.xlsx directly, so this only needs the new destination extension + dispatch case. Scope: PDF sources only. Image and Markdown sources are intentionally not wired up — those paths convert the OCR'd MMD via the /v1/export/* endpoints, and there is no /v1/export/xlsx endpoint. Supporting them would require backend work (a /v1/export/xlsx endpoint or rerouting those paths through v3/converter) and is left as a follow-up. Validated against the live API: POST /v3/pdf-file (file only) then GET /v3/pdf/{id}.xlsx returns a valid .xlsx (HTTP 200), matching the CLI's exact call pattern. Co-Authored-By: Claude Opus 4.8 (1M context) --- README.md | 6 +++++- lib/convert.js | 5 +++++ lib/mpx.js | 7 +++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 58812c5..7370f03 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,19 @@ mpx set-api-key ... # C:\Users\USERNAME\.mpx\config on Windows ``` -To digitize PDF's to editable Mathpix Markdown, docx, html or tex.zip: +To digitize PDF's to editable Mathpix Markdown, docx, xlsx, html or tex.zip: ``` mpx convert input-file.pdf output-file.mmd mpx convert input-file.pdf output-file.docx +mpx convert input-file.pdf output-file.xlsx mpx convert input-file.pdf output-file.tex mpx convert input-file.pdf output-file.html ``` +`xlsx` extracts tabular content (one worksheet per detected table) and is +currently supported for PDF sources only. + To digitize images to editable Mathpix Markdown, docx, html or tex.zip: ``` diff --git a/lib/convert.js b/lib/convert.js index ed0c324..76d63f9 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -432,6 +432,10 @@ async function PDFToDOCX(source, destination) { await ConvertPDF("docx", source, destination); } +async function PDFToXLSX(source, destination) { + await ConvertPDF("xlsx", source, destination); +} + async function PDFToTEX(source, destination) { await ConvertPDF("tex", source, `${destination}.zip`); } @@ -636,6 +640,7 @@ module.exports = { MarkdownToMarkdown, PDFToMMD, PDFToDOCX, + PDFToXLSX, PDFToTEX, PDFToHTML, ImageToMMD, diff --git a/lib/mpx.js b/lib/mpx.js index 2c7808f..66c55e1 100755 --- a/lib/mpx.js +++ b/lib/mpx.js @@ -103,7 +103,7 @@ program program .command("convert ") - .description("convert files between markdown, mathpix markdown, docx, latex and pdf formats") + .description("convert files between markdown, mathpix markdown, docx, xlsx, latex and pdf formats") .addOption( new commander.Option("-p, --pdf-method ", "choose to make pdf from latex or html") .choices(["latex", "html"]) @@ -133,7 +133,7 @@ program return process.exit(1); } - const validDestinationExtensions = [".mmd", ".md", ".pdf", ".tex", ".html", ".docx"]; + const validDestinationExtensions = [".mmd", ".md", ".pdf", ".tex", ".html", ".docx", ".xlsx"]; if (!validDestinationExtensions.includes(destinationExt)) { console.log( `Invalid destination extension, must be one of: ${JSON.stringify( @@ -163,6 +163,9 @@ program case sourceExt === ".pdf" && destinationExt === ".docx": await convert.PDFToDOCX(source, destination); break; + case sourceExt === ".pdf" && destinationExt === ".xlsx": + await convert.PDFToXLSX(source, destination); + break; case sourceExt === ".pdf" && destinationExt === ".tex": await convert.PDFToTEX(source, destination); break;