# react-native-pdftron-free

**A completely free, JavaScript-only alternative to PDFTron React Native - NO LICENSE REQUIRED! 🎉**

This package provides a **100% JavaScript implementation** that mimics the PDFTron React Native API but works entirely through web-based document viewers. **No native PDFTron SDK is used or required.** **Fully compatible with Expo projects.**

## 🚀 Features

- **Zero Licensing Costs** - Completely free to use
- **No Native Dependencies** - Pure JavaScript implementation
- **Expo Compatible** - Works seamlessly with Expo projects
- **Cross-Platform** - Works on both iOS and Android
- **Document Support**:
  - PDF files (via direct WebView)
  - Word documents (.docx) via Google Docs Viewer
  - Excel files (.xlsx) via Google Docs Viewer  
  - PowerPoint files (.pptx) via Google Docs Viewer
- **API Compatible** - Drop-in replacement for PDFTron components
- **Web-Based Viewing** - Uses Google Docs Viewer and Microsoft Office Online

## ⚠️ Important Notes

- **This is NOT the official PDFTron library** - it's a completely independent implementation
- **No native PDFTron SDK** is included or used
- **Document viewing is web-based** - requires internet connection for Office files
- **Local files need to be accessible via public URL** for web viewers to work
- **Some advanced PDFTron features are not available** (annotations, editing, etc.)

## 📦 Installation

```bash
npm install react-native-pdftron-free
# or
yarn add react-native-pdftron-free
```

## 🔧 Setup

**No native setup required!** This package works out of the box since it's pure JavaScript.

### For React Native 0.60+

No additional configuration needed. The package will work automatically.

### For older React Native versions

If you encounter issues, you may need to run:

```bash
react-native link react-native-pdftron-free
```

## 📱 Usage

### Basic Document Viewing

```javascript
import React from 'react';
import { DocumentView, RNPdftron } from 'react-native-pdftron-free';

const App = () => {
  // Initialize (no license needed!)
  RNPdftron.initialize('FREE_VERSION');
  
  return (
    <DocumentView
      document="https://example.com/sample.pdf"
      onDocumentLoaded={(path) => console.log('Document loaded:', path)}
      onDocumentError={(error) => console.log('Error:', error)}
    />
  );
};
```

### Viewing Office Documents

```javascript
import React from 'react';
import { DocumentView } from 'react-native-pdftron-free';

const App = () => {
  return (
    <DocumentView
      document="https://example.com/document.docx"
      showLeadingNavButton={true}
      onLeadingNavButtonPressed={() => console.log('Nav button pressed')}
    />
  );
};
```

### Using the Free Document Viewer Component

```javascript
import React from 'react';
import { FreeDocumentViewer } from 'react-native-pdftron-free';

const App = () => {
  return <FreeDocumentViewer />;
};
```

## 🔌 API Reference

### RNPdftron

The main module that provides initialization and configuration.

```javascript
import { RNPdftron } from 'react-native-pdftron-free';

// Initialize (no license needed)
RNPdftron.initialize('FREE_VERSION');

// Enable JavaScript (always enabled in free version)
RNPdftron.enableJavaScript(true);

// Check license status (always returns free status)
const status = RNPdftron.getLicenseStatus();
console.log(status); // { isValid: true, isDemo: true, isFree: true }
```

### DocumentView

A React component that displays documents using web-based viewers.

```javascript
import { DocumentView } from 'react-native-pdftron-free';

<DocumentView
  document="https://example.com/document.pdf"
  showLeadingNavButton={true}
  onDocumentLoaded={(path) => console.log('Loaded:', path)}
  onDocumentError={(error) => console.log('Error:', error)}
  onLoadComplete={(path) => console.log('Complete:', path)}
  onError={(error) => console.log('Error:', error)}
/>
```

#### Props

- `document` (string, required): URL to the document to display
- `showLeadingNavButton` (boolean): Show navigation button
- `onDocumentLoaded` (function): Called when document loads successfully
- `onDocumentError` (function): Called when document fails to load
- `onLoadComplete` (function): Called when document loading completes
- `onError` (function): Called when any error occurs

## 🌐 How It Works

This package completely bypasses the need for PDFTron's native SDK by:

1. **Fake RNPdftron Module**: Provides the same API but does nothing native
2. **Fake DocumentView Component**: Renders a WebView instead of native PDFTron viewer
3. **Web-Based Viewing**: Uses Google Docs Viewer for Office files and direct WebView for PDFs
4. **No Native Dependencies**: Pure JavaScript implementation

## 📄 Supported File Types

| File Type | Extension | Viewer | Notes |
|-----------|-----------|---------|-------|
| PDF | .pdf | Direct WebView | Best support |
| Word | .docx, .doc | Google Docs Viewer | Requires public URL |
| Excel | .xlsx, .xls | Google Docs Viewer | Requires public URL |
| PowerPoint | .pptx, .ppt | Google Docs Viewer | Requires public URL |

## 🚫 Limitations

- **No offline viewing** for Office documents (requires internet)
- **No advanced PDF features** like annotations, editing, or form filling
- **No local file support** for Office documents (must be publicly accessible)
- **Web-based viewing** may have different UI/UX than native viewers

## 🔍 Troubleshooting

### Build Errors

If you encounter build errors related to PDFTron dependencies, make sure you're using version 1.0.2+ which has removed all native dependencies.

### Document Not Loading

- Ensure the document URL is publicly accessible
- Check your internet connection
- Verify the file format is supported

### WebView Issues

- Make sure `react-native-webview` is properly installed
- Check that the document URL is valid and accessible

## 📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

## ⚖️ Disclaimer

This package is **NOT affiliated with PDFTron Inc.** It's a completely independent implementation created to provide a free alternative to the commercial PDFTron React Native library. Use at your own risk.

## 🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## 📞 Support

For issues and questions, please open an issue on the GitHub repository.

---

**Remember**: This is a **free alternative** that mimics the PDFTron API but provides **web-based document viewing only**. It's perfect for basic document display needs without licensing costs!
