feat: Add cleanup of temporary files in finalize command
- Remove all temporary PNG files after PDF creation - Remove temporary directory - Update command feedback messages
This commit is contained in:
+9
-3
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user