Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have .read_pdf() show us which page it is processing for large PDF files. #507

Open
bulrush15 opened this issue Sep 19, 2024 · 2 comments
Open

Comments

@bulrush15
Copy link

I may have PDF files of 400+ pages or more, each page with a table. We could use an option in .read_pdf() where Camelot tells us which page it is starting to process, or it has processed.

Alternatively, how can we make a loop to process one page at a time where I can print my own message to show which page is being processed.

@bosd
Copy link

bosd commented Sep 19, 2024

Hey!

As #343, we try to build a maintained fork at pypdf_table_extraction.

This specific feature is not implemented.
But there is support for parallel processing to speedup the process for large files. Which you may find usefull.

@bulrush15
Copy link
Author

bulrush15 commented Sep 20, 2024

Thank you @bosd. But we may end up processing many large files so in my status message I would still want to show the file I'm processing and the page that is being processed.

I may be able to process multiple pages in a loop like this:

# From Gemini AI. 
import camelot
import pandas as pd

# Replace 'your_pdf_file.pdf' with the actual path to your PDF file
pdf_file = 'your_pdf_file.pdf'

# Extract tables from the PDF file
tables = camelot.read_pdf(pdf_file)

# Iterate through the extracted tables
for table in tables:
    # Convert the table to a pandas DataFrame
    df = table.df

    # Save the DataFrame as a UTF-8 CSV file
    csv_file = 'output.csv'
    df.to_csv(csv_file, index=False, encoding='utf-8')

    print(f"Table {table.index} saved as {csv_file}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants