diff --git a/pdf_cleaner.py b/pdf_cleaner.py index 57a2a74..3bb3463 100755 --- a/pdf_cleaner.py +++ b/pdf_cleaner.py @@ -120,7 +120,8 @@ def deskew(): @cli.command() @click.argument('output_pdf', type=click.Path()) def finalize(output_pdf): - """Combine processed pages into final PDF.""" + """Combine processed pages into final PDF and clean up.""" + temp_dir = ensure_temp_dir() temp_files = get_temp_files() if not temp_files: print("No pages found in temporary directory. Run 'extract' first.") @@ -132,8 +133,13 @@ def finalize(output_pdf): with open(output_pdf, "wb") as f: f.write(img2pdf.convert(temp_files)) - print("PDF created successfully!") - print("Note: Temporary files were kept for further processing if needed.") + # Clean up temporary files + print("Cleaning up temporary files...") + for file_path in temp_files: + os.remove(file_path) + os.rmdir(temp_dir) + + print("PDF created successfully and temporary files removed!") if __name__ == '__main__': cli()