| name | pdf-calendar-extractor |
| description | Extract text and identifying colored regions (e.g., rectangles) from a PDF using pdfplumber. |
PDF Calendar Extractor
This skill provides a way to extract text elements and graphical shapes (like rectangles) from a PDF, including their positions and color properties. This is useful for processing visual calendars where appointments are represented by colored blocks.
Requirements
Example Usage: Extract Rectangles and Text
import pdfplumber
def extract_calendar_data(pdf_path):
with pdfplumber.open(pdf_path) as pdf:
page = pdf.pages[0]
text_elements = page.extract_text_full()
words = page.extract_words()
rects = page.rects
return words, rects
Tips for Measuring Time
If the calendar has horizontal lines representing 15-minute intervals:
- Identify all horizontal lines (
page.lines where y0 == y1).
- Sort them by vertical position (
top).
- Calculate the height of a 15-minute block.
- Map rectangle
top and bottom to specific times based on their position relative to the lines.