Spaces:
Sleeping
Sleeping
File size: 915 Bytes
16fb007 58144c9 16fb007 58144c9 16fb007 58144c9 16fb007 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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
|