Skip to main content

Extract comments, annotations, and structured content from PDF documents

Project description

PDF Comments Extractor

PyPI version Python Support License: MIT

A powerful Python package for extracting comments, annotations, and structured content from PDF documents. Perfect for analyzing supervisor feedback, extracting academic paper content, and processing annotated PDFs.

Features

  • 📝 Extract PDF Comments: Pull all annotations (highlights, sticky notes, text comments) from PDFs
  • 📄 Academic Paper Extraction: Extract structured content from research papers (sections, citations, references, figures, tables)
  • 🔍 Text Search: Search for specific text across PDFs with context
  • 💾 Multiple Output Formats: Export to JSON, CSV, or both
  • 🖥️ CLI Tools: Easy-to-use command-line interfaces
  • 🐍 Python API: Full programmatic access for integration into your workflows
  • 🌍 Multi-language Support: Works with any language including Hebrew, Arabic, Chinese, etc.

Installation

From PyPI (recommended)

pip install pdf-comments-extractor

From Source

git clone https://github.com/yourusername/pdf-comments-extractor.git
cd pdf-comments-extractor
pip install -e .

Quick Start

Command Line

Extract Comments from PDF

# Extract all comments
pdf-comments-extract paper.pdf

# With console output
pdf-comments-extract paper.pdf --print

# Specify output directory
pdf-comments-extract paper.pdf --output-dir ./my_comments

# Multiple files
pdf-comments-extract file1.pdf file2.pdf file3.pdf

Extract Academic Paper Content

# Extract all structured content
pdf-academic-extract paper.pdf --print

# JSON output only
pdf-academic-extract paper.pdf --format json

Search for Text in PDF

pdf-search paper.pdf "your search text"

Python API

Extract Comments

from pdf_comments_extractor import PDFCommentExtractor

# Using context manager (recommended)
with PDFCommentExtractor('paper.pdf') as extractor:
    comments = extractor.extract_all_comments()
    
    # Save to JSON
    extractor.save_to_json(comments, 'comments.json')
    
    # Save to CSV
    extractor.save_to_csv(comments, 'comments.csv')
    
    # Print summary
    extractor.print_summary(comments)

# Access individual comments
for comment in comments:
    print(f"Page {comment['page']}: {comment['comment']}")
    print(f"References: {comment['referenced_text']}")

Extract Academic Paper Content

from pdf_comments_extractor import AcademicPaperExtractor

extractor = AcademicPaperExtractor('paper.pdf')
data = extractor.extract_all()

# Access different components
print(f"Abstract: {data['sections']['Abstract']}")
print(f"Total citations: {data['statistics']['total_citations']}")

# Get all citations
for citation in data['citations']:
    print(f"{citation['author']} [{citation['year']}] on page {citation['page']}")

# Save results
extractor.save_to_json(data, 'paper_analysis.json')
extractor.close()

Search for Text

from pdf_comments_extractor import search_text_in_pdf

results = search_text_in_pdf('paper.pdf', 'neural networks')

for page_num, context in results:
    print(f"Found on page {page_num}:")
    print(context)

Output Format

Comment Extraction

Comments are extracted with the following information:

{
  "page": 1,
  "type": "Highlight",
  "subject": "Note",
  "author": "Reviewer Name",
  "comment": "This needs clarification",
  "referenced_text": "The text that was highlighted...",
  "position": {
    "x0": 100.5,
    "y0": 200.3,
    "x1": 300.2,
    "y1": 220.8
  },
  "created": "D:20231120120000",
  "modified": "D:20231120130000",
  "color": {"stroke": [1.0, 0.0, 0.0], "fill": null}
}

Academic Paper Extraction

Extracts comprehensive academic paper structure:

  • Metadata: Title, authors, page count, word count
  • Sections: Abstract, Introduction, Methodology, Results, Discussion, Conclusion
  • Citations: All citations with context and page numbers
  • References: Full bibliography
  • Figures & Tables: Captions and locations
  • Key Contributions: Identified contribution statements
  • Statistics: Complete metrics

Use Cases

1. Supervisor Feedback Analysis

# Extract all supervisor comments
with PDFCommentExtractor('thesis_reviewed.pdf') as extractor:
    comments = extractor.extract_all_comments()
    
# Filter by author
supervisor_comments = [c for c in comments if c['author'] == 'Dr. Smith']

# Group by page
from collections import defaultdict
by_page = defaultdict(list)
for comment in comments:
    by_page[comment['page']].append(comment)

2. Literature Review

# Extract citations from multiple papers
from pathlib import Path

all_citations = []
for pdf in Path('papers/').glob('*.pdf'):
    extractor = AcademicPaperExtractor(str(pdf))
    data = extractor.extract_all()
    all_citations.extend(data['citations'])
    extractor.close()

# Analyze citation patterns
from collections import Counter
authors = [c['author'] for c in all_citations]
most_cited = Counter(authors).most_common(10)

3. Multi-language Support

# Works with Hebrew, Arabic, Chinese, etc.
with PDFCommentExtractor('hebrew_manuscript.pdf') as extractor:
    comments = extractor.extract_all_comments()
    
for comment in comments:
    if 'לא מובן' in comment['comment']:  # "not clear" in Hebrew
        print(f"Clarity issue on page {comment['page']}")

Requirements

  • Python 3.7+
  • PyMuPDF (automatically installed)

Development

Setup Development Environment

git clone https://github.com/yourusername/pdf-comments-extractor.git
cd pdf-comments-extractor
pip install -e ".[dev]"

Run Tests

pytest tests/

Format Code

black pdf_comments_extractor/

Contributing

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

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

Citation

If you use this package in your research, please cite:

@software{pdf_comments_extractor,
  author = {Goldberg, Alexander},
  title = {PDF Comments Extractor},
  year = {2024},
  url = {https://github.com/yourusername/pdf-comments-extractor}
}

Acknowledgments

  • Built with PyMuPDF
  • Inspired by the need to efficiently process supervisor feedback on academic papers

Changelog

Version 0.1.0 (2024-11-29)

  • Initial release
  • PDF comment extraction
  • Academic paper content extraction
  • Search functionality
  • CLI tools
  • JSON and CSV export

Support

If you encounter any issues or have questions:

Related Projects


Made with ❤️ by Alexander Goldberg

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_comments_extractor-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf_comments_extractor-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file pdf_comments_extractor-0.1.0.tar.gz.

File metadata

  • Download URL: pdf_comments_extractor-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdf_comments_extractor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bdb651dee959e3aeb08086fcd94678bb5311f45572df3b00d85e1f1ebd190be
MD5 891dc3617adb45bc96f461bd9c1e0111
BLAKE2b-256 dd7aaf4fc57fa32b8cfbf39e5ff29aa0d9bc389d742b53ba00e028b9d5a16983

See more details on using hashes here.

File details

Details for the file pdf_comments_extractor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pdf_comments_extractor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52093336629e75ec717b97efb8c51ff73a23eee7332b87043aedf8f49c614063
MD5 f91ef028a652e0b0dbb8fbcfe224082d
BLAKE2b-256 6867beeb9fd474790ef31e2022a76d074829436e1b80ccfc809cec7d6103c9a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page