Skip to content

artnoricojr/split-panel-ui

Repository files navigation

Split Panel Viewer

A modular Python package that provides a split-screen interface for viewing PDF files alongside their corresponding JSON extracted content. Perfect for reviewing and validating PDF data extraction accuracy.

Features

  • Split-Screen Interface: View PDF and JSON files side by side
  • PDF Viewer:
    • Page navigation (previous/next)
    • Zoom in/out controls
    • Multi-page support
    • Smooth rendering using PyMuPDF
  • JSON Viewer:
    • Tree view for hierarchical navigation
    • Raw JSON view with syntax highlighting and line numbers (NEW!)
    • Table view for spreadsheet-like editing
    • Search functionality
    • Expandable/collapsible nodes
    • Advanced text editor with:
      • Line numbers display
      • Undo/Redo support (unlimited)
      • Find and Replace dialog
      • Case-sensitive and whole-word search options
    • Edit mode for modifying JSON data
    • Double-click cells to edit in table view
    • Real-time sync between table and JSON views
    • Auto-CSV export when saving
    • Auto-backup before saving changes
    • JSON validation before saving
    • Save and Save As functionality
  • User-Friendly:
    • File browser dialogs
    • Keyboard shortcuts
    • Auto-detection of matching files
    • Resizable panels
    • Status bar with feedback

Installation

Option 1: Install from source

# Clone or download the repository
cd split-panel-ui

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

Option 2: Install dependencies only

pip install PyMuPDF Pillow

Usage

Running as a standalone application

# Run with no files (use GUI to load)
python -m split_panel_viewer

# Or if installed
split-panel-viewer

Running with command-line arguments

# Load PDF only
python -m split_panel_viewer path/to/document.pdf

# Load both PDF and JSON
python -m split_panel_viewer path/to/document.pdf path/to/data.json

Using as a library

from split_panel_viewer import SplitPanelApp

# Create and run the application
app = SplitPanelApp()
app.run()

# Or with initial files
app = SplitPanelApp(
    pdf_file="document.pdf",
    json_file="data.json"
)
app.run()

Keyboard Shortcuts

File Operations

  • Ctrl+P - Open PDF file
  • Ctrl+J - Open JSON file
  • Ctrl+B - Open both files (with auto-detection)
  • Ctrl+L - Clear all loaded files
  • Ctrl+S - Save JSON changes (when in edit mode)
  • Ctrl+Q - Quit application

Text Editor (Raw JSON View)

  • Ctrl+Z - Undo
  • Ctrl+Y or Ctrl+Shift+Z - Redo
  • Ctrl+F - Find
  • Ctrl+H - Find and Replace

Package Structure

split-panel-ui/
├── split_panel_viewer/
│   ├── __init__.py          # Package initialization
│   ├── app.py               # Main application class
│   ├── components/
│   │   ├── __init__.py
│   │   ├── pdf_viewer.py    # PDF viewer component
│   │   └── json_viewer.py   # JSON viewer component
│   └── utils/
│       └── __init__.py
├── examples/                 # Example files (you can add samples here)
├── tests/                    # Unit tests (future)
├── requirements.txt          # Python dependencies
├── setup.py                  # Package setup configuration
└── README.md                 # This file

Components

PDFViewer

A reusable component for displaying PDF files with navigation and zoom controls.

from split_panel_viewer.components import PDFViewer

# In your Tkinter application
pdf_viewer = PDFViewer(parent_frame)
pdf_viewer.pack(fill=tk.BOTH, expand=True)
pdf_viewer.load_pdf("document.pdf")

Features:

  • Page-by-page navigation
  • Zoom controls (50% to 300%)
  • Scrollable canvas
  • Clean, intuitive interface

JSONViewer

A component for displaying JSON data in tree and text formats.

from split_panel_viewer.components import JSONViewer

# In your Tkinter application
json_viewer = JSONViewer(parent_frame)
json_viewer.pack(fill=tk.BOTH, expand=True)
json_viewer.load_json("data.json")

Features:

  • Tree view with expandable nodes
  • Raw JSON view with syntax highlighting
  • Search functionality
  • Tabbed interface for switching views
  • Edit mode for modifying JSON
  • Automatic backup creation before saving
  • Real-time JSON validation
  • Unsaved changes indicator

SplitPanelApp

The main application that combines both viewers.

from split_panel_viewer import SplitPanelApp

app = SplitPanelApp()
app.load_pdf("document.pdf")
app.load_json("data.json")
app.run()

Dependencies

  • PyMuPDF (fitz): PDF rendering and manipulation
  • Pillow (PIL): Image processing for PDF display
  • tkinter: GUI framework (included with Python)

Example Workflow

  1. Launch the application:

    python -m split_panel_viewer
  2. Load files:

    • Click "Load Both" button
    • Select your PDF file
    • The app will look for a matching .json file
    • Or manually select the JSON file
  3. Review content:

    • Navigate through PDF pages on the left
    • Browse JSON structure on the right
    • Use search to find specific content
    • Switch between tree and raw JSON views
  4. Edit JSON (if needed):

    • Click the "Edit" button in the JSON viewer
    • Modify the JSON content directly in the text view
    • The app will show a "● Modified" indicator
    • Press Ctrl+S or click "Save" to save changes
    • Automatic backup is created before saving (filename_backup_YYYYMMDD_HHMMSS.json)
    • JSON is validated before saving to prevent errors
  5. Verify accuracy:

    • Compare PDF content with extracted JSON data
    • Use zoom to examine PDF details
    • Expand JSON nodes to check nested data
    • Make corrections directly in edit mode

📝 Editing JSON Files: The viewer includes full editing capabilities with automatic backups. See EDITING_GUIDE.md for detailed instructions on editing, saving, and managing backups.

Creating Example Files

To test the viewer, you can create sample files:

Example JSON file (examples/sample.json)

{
  "title": "Sample Document",
  "pages": [
    {
      "page_number": 1,
      "content": "This is the first page",
      "metadata": {
        "extracted_at": "2024-01-15",
        "confidence": 0.95
      }
    }
  ],
  "summary": {
    "total_pages": 1,
    "word_count": 125
  }
}

Customization

The package is designed to be modular. You can:

  • Extend the viewers with additional features
  • Create custom styling with ttk themes
  • Add new file format support
  • Integrate with data extraction pipelines

Future Enhancements

Potential improvements for future versions:

  • Support for multiple file formats (XML, YAML, etc.)
  • Diff view to compare multiple JSON files
  • Export annotations and notes
  • Batch file processing
  • Plugin system for custom viewers
  • Dark mode theme
  • Configuration file support

Troubleshooting

PDF not displaying

  • Ensure PyMuPDF is installed: pip install PyMuPDF
  • Check if the PDF file is corrupted
  • Try a different PDF file

JSON not parsing

  • Validate your JSON file using a JSON validator
  • Check for encoding issues (file should be UTF-8)
  • Verify the file has a .json extension

Application crashes on startup

  • Verify all dependencies are installed
  • Check Python version (3.8+ required)
  • Try running with python -v for verbose output

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

License

MIT License - feel free to use this package in your projects.

Support

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


Note: This is an educational/development tool. For production use, consider adding error handling, logging, and additional validation features.

About

split panel pdf and json viewer to compare extracted content from pdf

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages