Spaces:
Sleeping
Sleeping
| import fitz # PyMuPDF | |
| from modules.vector_to_text import extract_and_replace_vector_data | |
| import os | |
| def process_pdf(input_pdf_path): | |
| """ | |
| Processes the PDF to replace vector data with editable text. | |
| """ | |
| output_pdf_path = os.path.join("static/output", "processed.pdf") | |
| # Ensure output directory exists | |
| os.makedirs("static/output", exist_ok=True) | |
| # Open the PDF | |
| pdf_document = fitz.open(input_pdf_path) | |
| # Iterate through each page and process vector data | |
| for page_number in range(len(pdf_document)): | |
| page = pdf_document[page_number] | |
| text_layer = extract_and_replace_vector_data(page) # Extract and replace vector data | |
| if text_layer: | |
| page.insert_text(fitz.Point(72, 72), text_layer, fontsize=12) # Add editable text | |
| # Save the modified PDF | |
| pdf_document.save(output_pdf_path) | |
| pdf_document.close() | |
| return output_pdf_path | |