pdf-highlighter/examples/single_pdf.py

27 lines
788 B
Python

import asyncio
from highlight_pdf.highlight_pdf import Highlighter
# PDF filename
pdf_filename = "example_pdf_document.pdf"
# Pages to consider (optional, can be None)
pages = [1, 2]
# Initialize the Highlighter
highlighter = Highlighter(
comment=True # Enable comments to understand the context
)
# Define the main asynchronous function to highlight the PDF
async def main():
highlighted_pdf_buffer = await highlighter.highlight(
user_input=input('User input: '), # e.g. what is said about climate?
pdf_filename=pdf_filename,
)
# Save the highlighted PDF to a new file
with open("highlighted_example_pdf_document.pdf", "wb") as f:
f.write(highlighted_pdf_buffer.getbuffer())
# Run the main function using asyncio
asyncio.run(main())