{"id":49215870,"url":"https://github.com/hashangit/extract2md","last_synced_at":"2026-04-24T00:02:00.447Z","repository":{"id":294547758,"uuid":"987316018","full_name":"hashangit/Extract2MD","owner":"hashangit","description":"Extract2MD is a powerful and versatile AI-enabled client-side JavaScript library for extracting text from PDF files and converting it into Markdown.","archived":false,"fork":false,"pushed_at":"2025-05-27T08:33:24.000Z","size":362,"stargazers_count":68,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-08T15:57:53.387Z","etag":null,"topics":["ai","browser","browser-based","client-side","js","llm","markdown","ocr","pdf","react","ts","wasm","webllm"],"latest_commit_sha":null,"homepage":"https://www.inferencequotient.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashangit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-20T22:41:23.000Z","updated_at":"2025-10-08T15:22:24.000Z","dependencies_parsed_at":"2025-05-21T00:37:14.756Z","dependency_job_id":null,"html_url":"https://github.com/hashangit/Extract2MD","commit_stats":null,"previous_names":["hashangit/extract2md"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hashangit/Extract2MD","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashangit%2FExtract2MD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashangit%2FExtract2MD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashangit%2FExtract2MD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashangit%2FExtract2MD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashangit","download_url":"https://codeload.github.com/hashangit/Extract2MD/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashangit%2FExtract2MD/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32203362,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-23T20:19:26.138Z","status":"ssl_error","status_checked_at":"2026-04-23T20:19:23.520Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","browser","browser-based","client-side","js","llm","markdown","ocr","pdf","react","ts","wasm","webllm"],"created_at":"2026-04-24T00:01:57.664Z","updated_at":"2026-04-24T00:02:00.438Z","avatar_url":"https://github.com/hashangit.png","language":"JavaScript","funding_links":["https://www.patreon.com/HashanWickramasinghe"],"categories":[],"sub_categories":[],"readme":"# Extract2MD - Enhanced PDF to Markdown Converter\n\n\u003c!-- Badges (Placeholder - Replace with actual badges) --\u003e\n[![NPM Version](https://img.shields.io/npm/v/extract2md.svg)](https://www.npmjs.com/package/extract2md)\n[![License](https://img.shields.io/npm/l/extract2md.svg)](https://github.com/hashangit/Extract2MD/blob/main/LICENSE)\n[![Downloads](https://img.shields.io/npm/dt/extract2md.svg)](https://www.npmjs.com/package/extract2md)\n\n[![Sponsor on Patreon](https://img.shields.io/badge/Sponsor%20on-Patreon-F96854?logo=patreon\u0026style=flat)](https://www.patreon.com/HashanWickramasinghe)\n\nA powerful client-side JavaScript library for converting PDFs to Markdown with multiple extraction methods and optional LLM enhancement. Now with scenario-specific methods for different use cases.\n\n![Extract2MD](https://github.com/user-attachments/assets/0704e80a-54bc-4449-a495-eb944a318400)\n\n## 🚀 Quick Start\n\nExtract2MD now offers 5 distinct scenarios for different conversion needs:\n\n```javascript\nimport Extract2MDConverter from 'extract2md';\n\n// Scenario 1: Quick conversion only\nconst markdown1 = await Extract2MDConverter.quickConvertOnly(pdfFile);\n\n// Scenario 2: High accuracy OCR conversion only  \nconst markdown2 = await Extract2MDConverter.highAccuracyConvertOnly(pdfFile);\n\n// Scenario 3: Quick conversion + LLM enhancement\nconst markdown3 = await Extract2MDConverter.quickConvertWithLLM(pdfFile);\n\n// Scenario 4: High accuracy conversion + LLM enhancement\nconst markdown4 = await Extract2MDConverter.highAccuracyConvertWithLLM(pdfFile);\n\n// Scenario 5: Combined extraction + LLM enhancement (most comprehensive)\nconst markdown5 = await Extract2MDConverter.combinedConvertWithLLM(pdfFile);\n```\n\n## 📋 Scenarios Explained\n\n### Scenario 1: Quick Convert Only\n- **Use case**: Fast conversion when PDF has selectable text\n- **Method**: `quickConvertOnly(pdfFile, config?)`\n- **Tech**: PDF.js text extraction only\n- **Output**: Basic markdown formatting\n\n### Scenario 2: High Accuracy Convert Only\n- **Use case**: PDFs with images, scanned documents, complex layouts\n- **Method**: `highAccuracyConvertOnly(pdfFile, config?)`\n- **Tech**: Tesseract.js OCR\n- **Output**: Markdown from OCR extraction\n\n### Scenario 3: Quick Convert + LLM\n- **Use case**: Fast extraction with AI enhancement for better formatting\n- **Method**: `quickConvertWithLLM(pdfFile, config?)`\n- **Tech**: PDF.js + WebLLM\n- **Output**: AI-enhanced markdown with improved structure and clarity\n\n### Scenario 4: High Accuracy + LLM\n- **Use case**: OCR extraction with AI enhancement\n- **Method**: `highAccuracyConvertWithLLM(pdfFile, config?)`\n- **Tech**: Tesseract.js OCR + WebLLM\n- **Output**: AI-enhanced markdown from OCR\n\n### Scenario 5: Combined + LLM (Recommended)\n- **Use case**: Most comprehensive conversion using both extraction methods\n- **Method**: `combinedConvertWithLLM(pdfFile, config?)`\n- **Tech**: PDF.js + Tesseract.js + WebLLM with specialized prompts\n- **Output**: Best possible markdown leveraging strengths of both extraction methods\n\n## ⚙️ Configuration\n\nCreate a configuration object or JSON file to customize behavior:\n\n```javascript\nconst config = {\n  // PDF.js Worker\n  pdfJsWorkerSrc: \"../pdf.worker.min.mjs\",\n  \n  // Tesseract OCR Settings\n  tesseract: {\n    workerPath: \"./tesseract-worker.min.js\",\n    corePath: \"./tesseract-core.wasm.js\", \n    langPath: \"./lang-data/\",\n    language: \"eng\",\n    options: {}\n  },\n  \n  // LLM Configuration\n  webllm: {\n    model: \"Qwen3-0.6B-q4f16_1-MLC\",\n    // Optional: Custom model\n    customModel: {\n      model: \"https://huggingface.co/mlc-ai/your-model/resolve/main/\",\n      model_id: \"YourModel-ID\",\n      model_lib: \"https://example.com/your-model.wasm\",\n      required_features: [\"shader-f16\"],\n      overrides: { conv_template: \"qwen\" }\n    },\n    options: {\n      temperature: 0.7,\n      maxTokens: 4096\n    }\n  },\n  \n  // System Prompt Customizations\n  systemPrompts: {\n    singleExtraction: \"Focus on preserving code examples exactly.\",\n    combinedExtraction: \"Pay attention to tables and diagrams from OCR.\"\n  },\n  \n  // Processing Options\n  processing: {\n    splitPascalCase: false,\n    pdfRenderScale: 2.5,\n    postProcessRules: [\n      { find: /\\bAPI\\b/g, replace: \"API\" }\n    ]\n  },\n  \n  // Progress Tracking\n  progressCallback: (progress) =\u003e {\n    console.log(`${progress.stage}: ${progress.message}`);\n    if (progress.currentPage) {\n      console.log(`Page ${progress.currentPage}/${progress.totalPages}`);\n    }\n  }\n};\n\n// Use configuration\nconst markdown = await Extract2MDConverter.combinedConvertWithLLM(pdfFile, config);\n```\n\n## 🔧 Advanced Usage\n\n### Using Individual Components\n\n```javascript\nimport { \n  WebLLMEngine, \n  OutputParser, \n  SystemPrompts,\n  ConfigValidator \n} from 'extract2md';\n\n// Validate configuration\nconst validatedConfig = ConfigValidator.validate(userConfig);\n\n// Initialize WebLLM engine\nconst engine = new WebLLMEngine(validatedConfig);\nawait engine.initialize();\n\n// Generate text\nconst result = await engine.generate(\"Your prompt here\");\n\n// Parse output\nconst parser = new OutputParser();\nconst cleanMarkdown = parser.parse(result);\n```\n\n### Custom System Prompts\n\nThe library uses different system prompts for different scenarios:\n\n```javascript\n// For scenarios 3 \u0026 4 (single extraction)\nconst singlePrompt = SystemPrompts.getSingleExtractionPrompt(\n  \"Additional instruction: Preserve all technical terms.\"\n);\n\n// For scenario 5 (combined extraction) \nconst combinedPrompt = SystemPrompts.getCombinedExtractionPrompt(\n  \"Focus on creating comprehensive documentation.\"\n);\n```\n\n### Configuration from JSON\n\n```javascript\nimport { ConfigValidator } from 'extract2md';\n\n// Load from JSON string\nconst config = ConfigValidator.fromJSON(configJsonString);\n\n// Use with any scenario\nconst result = await Extract2MDConverter.quickConvertWithLLM(pdfFile, config);\n```\n\n## 🎯 Error Handling \u0026 Progress Tracking\n\n```javascript\nconst config = {\n  progressCallback: (progress) =\u003e {\n    switch (progress.stage) {\n      case 'scenario_5_start':\n        console.log('Starting combined conversion...');\n        break;\n      case 'webllm_load_progress':\n        console.log(`Loading model: ${progress.progress}%`);\n        break;\n      case 'ocr_page_process':\n        console.log(`OCR: ${progress.currentPage}/${progress.totalPages}`);\n        break;\n      case 'webllm_generate_start':\n        console.log('AI enhancement in progress...');\n        break;\n      case 'scenario_5_complete':\n        console.log('Conversion completed!');\n        break;\n      default:\n        console.log(`${progress.stage}: ${progress.message}`);\n    }\n    \n    if (progress.error) {\n      console.error('Error:', progress.error);\n    }\n  }\n};\n\ntry {\n  const result = await Extract2MDConverter.combinedConvertWithLLM(pdfFile, config);\n  console.log('Success:', result);\n} catch (error) {\n  console.error('Conversion failed:', error.message);\n}\n```\n\n## 🔄 Migration from Legacy API\n\nIf you're using the old API, you can still access it:\n\n```javascript\nimport { LegacyExtract2MDConverter } from 'extract2md';\n\n// Old way\nconst converter = new LegacyExtract2MDConverter(options);\nconst quick = await converter.quickConvert(pdfFile);\nconst ocr = await converter.highAccuracyConvert(pdfFile);\nconst enhanced = await converter.llmRewrite(text);\n\n// New way (recommended)\nconst quick = await Extract2MDConverter.quickConvertOnly(pdfFile, config);\nconst ocr = await Extract2MDConverter.highAccuracyConvertOnly(pdfFile, config);\nconst enhanced = await Extract2MDConverter.quickConvertWithLLM(pdfFile, config);\n```\n\n## 🌟 Features\n\n- **5 Scenario-Specific Methods**: Choose the right approach for your use case\n- **WebLLM Integration**: Client-side AI enhancement with Qwen models\n- **Custom Model Support**: Use your own trained models\n- **Advanced Output Parsing**: Automatic removal of thinking tags and formatting\n- **Comprehensive Configuration**: Fine-tune every aspect of the conversion\n- **Progress Tracking**: Real-time updates for UI integration\n- **TypeScript Support**: Full type definitions included\n- **Backwards Compatible**: Legacy API still available\n\n## 📚 TypeScript Support\n\nFull TypeScript definitions are included:\n\n```typescript\nimport Extract2MDConverter, { \n  Extract2MDConfig, \n  ProgressReport,\n  CustomModelConfig \n} from 'extract2md';\n\nconst config: Extract2MDConfig = {\n  webllm: {\n    model: \"Qwen3-0.6B-q4f16_1-MLC\",\n    options: {\n      temperature: 0.7,\n      maxTokens: 4096\n    }\n  },\n  progressCallback: (progress: ProgressReport) =\u003e {\n    console.log(progress.stage, progress.message);\n  }\n};\n\nconst result: string = await Extract2MDConverter.combinedConvertWithLLM(pdfFile, config);\n```\n\n## 🏗️ Installation \u0026 Deployment\n\n### NPM Installation\n```bash\nnpm install extract2md\n```\n\n### CDN Usage\n```html\n\u003cscript src=\"https://unpkg.com/extract2md@2.0.0/dist/assets/extract2md.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    // Available as global Extract2MD\n    const result = await Extract2MD.Extract2MDConverter.quickConvertOnly(pdfFile);\n\u003c/script\u003e\n```\n\n### Worker Files Configuration\nThe package requires worker files for PDF.js and Tesseract.js. These are automatically copied during build:\n\n```javascript\n// Default worker paths (adjust for your deployment)\nconst config = {\n    pdfJsWorkerSrc: \"/pdf.worker.min.mjs\",\n    tesseract: {\n        workerPath: \"/tesseract-worker.min.js\",\n        corePath: \"/tesseract-core.wasm.js\"\n    }\n};\n```\n\n### Bundle Size Considerations\n- **Total Size**: ~11 MB (includes OCR and PDF processing)\n- **PDF.js**: ~950 KB\n- **Tesseract.js**: ~4.5 MB \n- **WebLLM**: Variable (model-dependent)\n\nUse lazy loading and code splitting for production deployments.\n\n## 📚 Documentation\n\n- **[Migration Guide](./MIGRATION.md)** - Upgrade from legacy API\n- **[Deployment Guide](./DEPLOYMENT.md)** - Production deployment instructions\n- **[Examples](./examples/)** - Complete usage examples\n- **[How To Run the Demo](./examples/README.md)** - Instructions on how to run the demo\n- **[TypeScript Definitions](./src/types/index.d.ts)** - Full type definitions\n\n## 📄 License\n\nMIT License - see LICENSE file for details.\n\n## 🤝 Contributing\n\nContributions welcome! Please read the contributing guidelines before submitting PRs.\n\n## 🐛 Issues\n\nReport issues on the [GitHub Issues page](https://github.com/hashangit/Extract2MD/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashangit%2Fextract2md","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashangit%2Fextract2md","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashangit%2Fextract2md/lists"}