{"_id":"@paul_sizon/expo-pdf-text-extract","name":"@paul_sizon/expo-pdf-text-extract","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@paul_sizon/expo-pdf-text-extract","version":"1.0.1","description":"Native PDF text extraction for React Native and Expo. Extract text content from PDF files using platform-native APIs (PDFKit on iOS, PDFBox on Android). Works with Expo development builds.","main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","source":"src/index.ts","scripts":{"build":"tsc","prepublishOnly":"npm run clean && npm run build","clean":"rm -rf dist"},"keywords":["react-native","expo","pdf","pdf-extraction","pdf-text","text-extraction","native-module","expo-module","pdfkit","pdfbox","document-processing","ocr-alternative","ios","android","expo-module","pdf-parser","pdf-reader","document-scanner"],"author":{"name":"Paul Sizon"},"contributors":[{"name":"Pathik Gandhi","email":"pathikgandhi@gmail.com"}],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Paul-Sizon/expo-pdf-text-extract.git"},"homepage":"https://github.com/Paul-Sizon/expo-pdf-text-extract#readme","bugs":{"url":"https://github.com/Paul-Sizon/expo-pdf-text-extract/issues"},"engines":{"node":">=16.0.0"},"peerDependencies":{"expo":">=49.0.0","react":">=18.0.0","react-native":">=0.72.0"},"devDependencies":{"expo-modules-core":"~2.4.1","typescript":"^5.0.0"},"_id":"@paul_sizon/expo-pdf-text-extract@1.0.1","gitHead":"7ba8b5a9eaac6cecadbf4996a7a8d9d521cccf9b","_nodeVersion":"24.5.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-t99YbFzfMHb4ulQg5Pwyg2yuA0Gu48ipjvyZrtEu27yXhOd0VfTYCIX6ng9HtIImxc/LBv3H3DYcIRVisHQi8A==","shasum":"3017f70d344ba010e46030d7952f6b0840ff781b","tarball":"https://registry.npmjs.org/@paul_sizon/expo-pdf-text-extract/-/expo-pdf-text-extract-1.0.1.tgz","fileCount":16,"unpackedSize":68722,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIC4PZmFdTMi9NDXrXRQRBrvMq1spKLzMkTBy+FyoLQKiAiEA6MYqkIBZfJDpGWM9Y/ibcYwICHKi0SNUWYGXI9o93yA="}]},"_npmUser":{"name":"paul_sizon","email":"paul.sizon@outlook.com"},"directories":{},"maintainers":[{"name":"paul_sizon","email":"paul.sizon@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/expo-pdf-text-extract_1.0.1_1778012025777_0.6259140241317478"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-05T20:13:45.692Z","1.0.1":"2026-05-05T20:13:45.933Z","modified":"2026-05-05T20:13:46.126Z"},"maintainers":[{"name":"paul_sizon","email":"paul.sizon@outlook.com"}],"description":"Native PDF text extraction for React Native and Expo. Extract text content from PDF files using platform-native APIs (PDFKit on iOS, PDFBox on Android). Works with Expo development builds.","homepage":"https://github.com/Paul-Sizon/expo-pdf-text-extract#readme","keywords":["react-native","expo","pdf","pdf-extraction","pdf-text","text-extraction","native-module","expo-module","pdfkit","pdfbox","document-processing","ocr-alternative","ios","android","expo-module","pdf-parser","pdf-reader","document-scanner"],"repository":{"type":"git","url":"git+https://github.com/Paul-Sizon/expo-pdf-text-extract.git"},"contributors":[{"name":"Pathik Gandhi","email":"pathikgandhi@gmail.com"}],"author":{"name":"Paul Sizon"},"bugs":{"url":"https://github.com/Paul-Sizon/expo-pdf-text-extract/issues"},"license":"MIT","readme":"# expo-pdf-text-extract\n\nNative PDF text extraction for React Native and Expo. Extract text content from PDF files using platform-native APIs - no OCR needed for digital PDFs.\n\n[![npm version](https://img.shields.io/npm/v/expo-pdf-text-extract.svg)](https://www.npmjs.com/package/expo-pdf-text-extract)\n[![license](https://img.shields.io/npm/l/expo-pdf-text-extract.svg)](https://github.com/gr8pathik/expo-pdf-text-extract/blob/main/LICENSE)\n[![platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20Android-lightgrey.svg)](https://reactnative.dev/)\n\n## Features\n\n- **Native Performance** - Uses PDFKit (iOS) and PDFBox (Android) for fast, reliable extraction\n- **No OCR Required** - Extracts embedded text directly from digital PDFs\n- **Expo Compatible** - Works with Expo development builds (SDK 49+)\n- **TypeScript Support** - Full type definitions included\n- **Simple API** - Just one function to extract text\n- **Page-level Control** - Extract from specific pages or get page count\n- **Multiple Path Formats** - Supports `file://`, `content://`, and absolute paths\n\n## When to Use This\n\n| Scenario | This Package | Alternative |\n|----------|-------------|-------------|\n| Digital PDFs (from email, downloads) | Yes | - |\n| Scanned PDFs (images of paper) | No | Use OCR library |\n| Need text content only | Yes | - |\n| Need to render/view PDF | No | Use react-native-pdf |\n| Expo Go | No | Requires dev build |\n\n## Requirements\n\n- **Expo SDK**: 49.0.0 or higher\n- **React Native**: 0.72.0 or higher\n- **iOS**: 15.1 or higher\n- **Android**: API 21 (Lollipop) or higher\n\n> **Important**: This package requires an Expo development build. It will not work in Expo Go.\n\n## Installation\n\n### Using Expo\n\n```bash\nnpx expo install expo-pdf-text-extract\n```\n\n### Using npm/yarn\n\n```bash\nnpm install expo-pdf-text-extract\n# or\nyarn add expo-pdf-text-extract\n```\n\n### Create Development Build\n\nSince this is a native module, you need to create a development build:\n\n```bash\n# For iOS\nnpx expo run:ios\n\n# For Android\nnpx expo run:android\n\n# Or create a development build\neas build --profile development --platform all\n```\n\n## Quick Start\n\n```typescript\nimport { extractText, isAvailable } from 'expo-pdf-text-extract';\n\n// Check if native module is available\nif (isAvailable()) {\n  // Extract text from a PDF file\n  const text = await extractText('/path/to/document.pdf');\n  console.log(text);\n}\n```\n\n## API Reference\n\n### `isAvailable()`\n\nCheck if the native PDF extractor is available.\n\n```typescript\nfunction isAvailable(): boolean\n```\n\nReturns `false` when:\n- Running in Expo Go\n- Native module failed to load\n- Platform not supported\n\n**Example:**\n```typescript\nimport { isAvailable } from 'expo-pdf-text-extract';\n\nif (isAvailable()) {\n  // Show PDF upload option\n} else {\n  // Show message: \"PDF extraction requires a development build\"\n}\n```\n\n### `extractText(filePath)`\n\nExtract all text from a PDF file.\n\n```typescript\nfunction extractText(filePath: string): Promise<string>\n```\n\n**Parameters:**\n- `filePath` - Path to the PDF file. Supports:\n  - `file:///path/to/file.pdf` - File URI\n  - `/absolute/path/to/file.pdf` - Absolute path\n  - `content://...` - Content URI (Android document picker)\n\n**Returns:** Promise resolving to extracted text\n\n**Throws:**\n- Error if native module not available\n- Error if file not found\n- Error if PDF is invalid or corrupted\n\n**Example:**\n```typescript\nimport { extractText } from 'expo-pdf-text-extract';\nimport * as DocumentPicker from 'expo-document-picker';\n\n// Pick a PDF file\nconst result = await DocumentPicker.getDocumentAsync({\n  type: 'application/pdf',\n});\n\nif (!result.canceled) {\n  const text = await extractText(result.assets[0].uri);\n  console.log('Extracted text:', text);\n}\n```\n\n### `getPageCount(filePath)`\n\nGet the number of pages in a PDF.\n\n```typescript\nfunction getPageCount(filePath: string): Promise<number>\n```\n\n**Example:**\n```typescript\nimport { getPageCount } from 'expo-pdf-text-extract';\n\nconst pages = await getPageCount('/path/to/document.pdf');\nconsole.log(`PDF has ${pages} pages`);\n```\n\n### `extractTextFromPage(filePath, pageNumber)`\n\nExtract text from a specific page.\n\n```typescript\nfunction extractTextFromPage(filePath: string, pageNumber: number): Promise<string>\n```\n\n**Parameters:**\n- `filePath` - Path to the PDF file\n- `pageNumber` - Page number (1-indexed, first page is 1)\n\n**Example:**\n```typescript\nimport { extractTextFromPage, getPageCount } from 'expo-pdf-text-extract';\n\n// Extract text from first page only\nconst firstPageText = await extractTextFromPage('/path/to/document.pdf', 1);\n\n// Extract text from each page separately\nconst pageCount = await getPageCount('/path/to/document.pdf');\nfor (let i = 1; i <= pageCount; i++) {\n  const pageText = await extractTextFromPage('/path/to/document.pdf', i);\n  console.log(`Page ${i}:`, pageText);\n}\n```\n\n### `extractTextWithInfo(filePath)`\n\nExtract text with additional metadata.\n\n```typescript\nfunction extractTextWithInfo(filePath: string): Promise<{\n  text: string;\n  pageCount: number;\n  success: boolean;\n  error?: string;\n}>\n```\n\n**Example:**\n```typescript\nimport { extractTextWithInfo } from 'expo-pdf-text-extract';\n\nconst result = await extractTextWithInfo('/path/to/document.pdf');\n\nif (result.success) {\n  console.log(`Extracted ${result.text.length} characters from ${result.pageCount} pages`);\n} else {\n  console.error('Extraction failed:', result.error);\n}\n```\n\n## Usage with Document Picker\n\n```typescript\nimport { extractText, isAvailable } from 'expo-pdf-text-extract';\nimport * as DocumentPicker from 'expo-document-picker';\n\nasync function handlePdfUpload() {\n  // Check if extraction is available\n  if (!isAvailable()) {\n    Alert.alert(\n      'Not Available',\n      'PDF extraction requires a development build. Please rebuild the app.'\n    );\n    return;\n  }\n\n  // Pick PDF file\n  const result = await DocumentPicker.getDocumentAsync({\n    type: 'application/pdf',\n    copyToCacheDirectory: true,\n  });\n\n  if (result.canceled) {\n    return;\n  }\n\n  try {\n    // Extract text\n    const text = await extractText(result.assets[0].uri);\n\n    // Use the extracted text\n    console.log('Extracted text:', text.substring(0, 500));\n\n    // Parse the text, search for patterns, etc.\n    const hasKeyword = text.includes('invoice');\n\n  } catch (error) {\n    Alert.alert('Error', `Failed to extract text: ${error.message}`);\n  }\n}\n```\n\n## Error Handling\n\n```typescript\nimport { extractText, isAvailable } from 'expo-pdf-text-extract';\n\nasync function safeExtract(filePath: string): Promise<string | null> {\n  // Check availability first\n  if (!isAvailable()) {\n    console.warn('PDF extraction not available');\n    return null;\n  }\n\n  try {\n    return await extractText(filePath);\n  } catch (error) {\n    if (error.message.includes('not found')) {\n      console.error('File not found:', filePath);\n    } else if (error.message.includes('PDF_LOAD_ERROR')) {\n      console.error('Invalid or corrupted PDF');\n    } else {\n      console.error('Extraction failed:', error.message);\n    }\n    return null;\n  }\n}\n```\n\n## Platform Differences\n\n### iOS (PDFKit)\n- Uses Apple's native PDFKit framework\n- Built into iOS, no additional dependencies\n- Excellent support for standard PDF formats\n- Minimum iOS version: 15.1\n\n### Android (PDFBox)\n- Uses Apache PDFBox (Android port)\n- Text is sorted by position on page for better readability\n- Handles compressed PDF streams (FlateDecode, etc.)\n- Minimum API level: 21\n\n## Troubleshooting\n\n### \"PDF extraction is not available\"\n\nThis error occurs when running in Expo Go. Solution:\n\n```bash\n# Create a development build\nnpx expo run:ios\n# or\nnpx expo run:android\n```\n\n### Empty text returned\n\nIf `extractText()` returns empty string:\n1. **Scanned PDF** - The PDF contains images, not text. Use OCR instead.\n2. **Protected PDF** - The PDF has copy protection. Text extraction may be blocked.\n3. **Corrupted PDF** - Try opening the PDF in another app to verify it's valid.\n\n### Slow extraction on large PDFs\n\nFor PDFs with many pages, consider:\n1. Extract page by page using `extractTextFromPage()`\n2. Show progress indicator to users\n3. Process in background using a worker\n\n## Performance\n\n| PDF Size | Pages | Extraction Time (approx) |\n|----------|-------|--------------------------|\n| Small    | 1-5   | < 100ms |\n| Medium   | 10-50 | 100-500ms |\n| Large    | 100+  | 500ms-2s |\n\n*Times measured on iPhone 13 and Pixel 6*\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines before submitting PRs.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n\n## Credits\n\n- iOS implementation uses Apple's [PDFKit](https://developer.apple.com/documentation/pdfkit)\n- Android implementation uses [PDFBox-Android](https://github.com/TomRoush/PdfBox-Android) by Tom Roush\n\n## Related Packages\n\n- [expo-document-picker](https://docs.expo.dev/versions/latest/sdk/document-picker/) - Pick documents from device\n- [react-native-pdf](https://github.com/wonday/react-native-pdf) - Display PDFs (viewing, not extraction)\n- [pdf-lib](https://pdf-lib.js.org/) - Create and modify PDFs in JavaScript\n","readmeFilename":"README.md","_rev":"1-c6456f4ed534ea7ac7171c18ebbb326b"}