Skip to content

Instantly share code, notes, and snippets.

@Intelrunner
Last active May 8, 2024 13:28
Show Gist options
  • Select an option

  • Save Intelrunner/654df57f0fb27818001ccebb7e4e3b75 to your computer and use it in GitHub Desktop.

Select an option

Save Intelrunner/654df57f0fb27818001ccebb7e4e3b75 to your computer and use it in GitHub Desktop.

Revisions

  1. Intelrunner revised this gist May 8, 2024. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion convert_pdf.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,17 @@
    """
    Instructions
    - Download to folder
    - > Run "pip3 freeze > requirements.txt"
    - > Run pip3 "install -r requirements.txt"
    - > run python3 -m main.py
    - Enjoy
    """

    from tabula import convert_into, read_pdf
    import os
    import tabula
    # ask for the file name
    file_name = input("Enter the file name: ")
    file_name = input("Enter the file name or relative path: ")

    df = tabula.read_pdf(file_name, pages="all", encoding='utf-8', multiple_tables=False)
    if not os.path.exists("output"):
  2. Intelrunner created this gist May 8, 2024.
    18 changes: 18 additions & 0 deletions convert_pdf.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    from tabula import convert_into, read_pdf
    import os
    import tabula
    # ask for the file name
    file_name = input("Enter the file name: ")

    df = tabula.read_pdf(file_name, pages="all", encoding='utf-8', multiple_tables=False)
    if not os.path.exists("output"):
    os.makedirs("output")
    print("Directory created")
    for i, table in enumerate(df):
    table.to_csv(f"output/table_{i}.csv", index=False)
    print(f"Table {i} saved to CSV")
    else:
    print("Directory already exists")
    for i, table in enumerate(df):
    table.to_csv(f"output/table_{i}.csv", index=False)
    print(f"Table {i} saved to CSV")