A fast, helpful, and open-source document parser
fix: windows adjustements
Astra Clelia Bertelli2d5857f5eda1
diff --git a/README.md b/README.mdindex 97b4339..b24defd 100644--- a/README.md+++ b/README.md@@ -238,8 +238,13 @@ brew install --cask libreoffice# Ubuntu/Debianapt-get install libreoffice++# Windows+choco install libreoffice-fresh # might require admin permissions```+> _For Windows, you might need to add the path to the directory containing LibreOffice CLI executable (generally `C:\Program Files\LibreOffice\program`) to the environment variables and re-start the machine._+#### Images (via ImageMagick)- **Formats**: `.jpg`, `.jpeg`, `.png`, `.gif`, `.bmp`, `.tiff`, `.webp`, `.svg`@@ -251,6 +256,9 @@ brew install imagemagick# Ubuntu/Debianapt-get install imagemagick++# Windows+choco install imagemagick.app # might require admin permissions```## Configuration@@ -300,9 +308,12 @@ We provide a fairly rich `AGENTS.md`/`CLAUDE.md` that we recommend using to help# Install dependenciesnpm install-# Build TypeScript+# Build TypeScript (Linux/macOs)npm run build+# Build Typescript (Windows)+npm run build:windows+# Watch modenpm run devdiff --git a/package.json b/package.jsonindex 48efc40..0822398 100644--- a/package.json+++ b/package.json@@ -24,7 +24,9 @@],"scripts": {"build": "tsc && npm run copy-vendor",+ "build:windows": "tsc && npm run copy-vendor:windows","copy-vendor": "mkdir -p dist/src/vendor && cp -r src/vendor/pdfjs dist/src/vendor/",+ "copy-vendor:windows": "powershell -Command \"New-Item -ItemType Directory -Path dist/src/vendor -Force; Copy-Item -Recurse src/vendor/pdfjs dist/src/vendor/\"","dev": "tsc --watch","test": "vitest run","test:watch": "vitest",diff --git a/src/conversion/convertToPdf.ts b/src/conversion/convertToPdf.tsindex 12d0935..6f976a3 100644--- a/src/conversion/convertToPdf.ts+++ b/src/conversion/convertToPdf.ts@@ -146,6 +146,15 @@ async function executeCommand(command: string, args: string[], timeoutMs = 60000});}+/* Execute a command for PowerShell */+async function executePowerShell(command: string, timeoutMs = 60000) {+ return executeCommand(+ "powershell",+ ["-NoProfile", "-Command", command],+ timeoutMs+ );+}+/*** Check if a command is available*/@@ -158,6 +167,15 @@ async function isCommandAvailable(command: string): Promise<boolean> {}}+async function isCommandAvailableWindows(command: string): Promise<boolean> {+ try {+ await executePowerShell(`Get-Command ${command}`, 5000);+ return true;+ } catch {+ return false;+ }+}+/*** Check if a file path exists and is executable*/@@ -175,12 +193,12 @@ async function isPathExecutable(filePath: string): Promise<boolean> {*/export async function findLibreOfficeCommand(): Promise<string | null> {// Check for 'libreoffice' in PATH (Linux, some macOS setups)- if (await isCommandAvailable("libreoffice")) {+ if (await isCommandAvailable("libreoffice") || await isCommandAvailableWindows("libreoffice")) {return "libreoffice";}// Check for 'soffice' in PATH- if (await isCommandAvailable("soffice")) {+ if (await isCommandAvailable("soffice") || await isCommandAvailableWindows("soffice")) {return "soffice";}@@ -190,12 +208,22 @@ export async function findLibreOfficeCommand(): Promise<string | null> {"/Applications/LibreOffice.app/Contents/MacOS/libreoffice",];+ const windowsPaths = [+ "C:\\Program Files\\Libreoffice\\program\\soffice.exe"+ ]+for (const libPath of macOSPaths) {if (await isPathExecutable(libPath)) {return libPath;}}+ for (const libPath of windowsPaths) {+ if (await isPathExecutable(libPath)) {+ return libPath;+ }+ }+return null;}@@ -207,12 +235,12 @@ export async function findImageMagickCommand(): Promise<{args: string[];} | null> {// ImageMagick v7 uses 'magick' command- if (await isCommandAvailable("magick")) {+ if (await isCommandAvailable("magick") || await isCommandAvailableWindows("magick")) {return { command: "magick", args: [] };}// ImageMagick v6 uses 'convert' command- if (await isCommandAvailable("convert")) {+ if (await isCommandAvailable("convert") || await isCommandAvailableWindows("convert")) {return { command: "convert", args: [] };}diff --git a/src/engines/pdf/pdfjsImporter.ts b/src/engines/pdf/pdfjsImporter.tsindex 905aa46..1f0b308 100644--- a/src/engines/pdf/pdfjsImporter.ts+++ b/src/engines/pdf/pdfjsImporter.ts@@ -1,17 +1,9 @@-import { fileURLToPath } from "node:url";-import { dirname, join } from "node:path";-export async function importPdfJs() {- // Dynamic import of PDF.js- const __filename = fileURLToPath(import.meta.url);- const __dirname = dirname(__filename);- // From dist/src/engines/pdf/ we need to go up to dist/src/vendor/pdfjs- const PDFJS_DIR = join(__dirname, "../../vendor/pdfjs");-- // Import PDF.js dynamically- await import(`${PDFJS_DIR}/pdf.mjs`);- const pdfjs = await import(`${PDFJS_DIR}/pdf.mjs`);- const { getDocument } = pdfjs;+ const pdfUrl = new URL("../../vendor/pdfjs/pdf.mjs", import.meta.url);+ const pdfjs = await import(pdfUrl.href);- return { fn: getDocument, dir: PDFJS_DIR };-}+ return {+ fn: pdfjs.getDocument,+ dir: pdfUrl+ };+}\ No newline at end of filediff --git a/test.docx b/test.docxnew file mode 100644index 0000000..da3d677Binary files /dev/null and b/test.docx differ