Closed stefan6419846 closed 2 years ago
So to clarify, if you don't use pdftocairo the directory is cleaned up even if pdf2image raises an exception?
No:
Ok now I remember (I wrote that part of the code a while ago so my memory can be spotty at times). This behaviour is caused by pdftocairo
not having stdout. It will automatically generate files on disk instead of in memory which is the pdftoppm
behaviour.
I agree that the temp directory should be discarded on exception, I will add a try/except to handle this edge case.
The PR should fix your issue and make the behaviour coherent, will be merging and releasing this soon.
Describe the bug
If pdf2image is used with
use_pdftocairo=True
, a temporary output directory is being created if I am not passing one myself. This directory will not be cleaned up when an error occurs during runtime.To Reproduce
Steps to reproduce the behavior:
Generate a faulty PDF (example: PDF with a PNG image that includes a color profile, as Pillow is not able to read such files).
pdf2image.convert_from_path(pdf_path, use_pdftocairo=True)
Error is produced:
Directory
/tmp/tmpvn5xet47/
is not being removed.Expected behavior
pdf2image should be more transparent about the side-effects of the
use_pdftocairo
option. Ideally auto-created temporary directories would always be cleaned up in case of an error or at least accessible to the caller in some way to perform manual cleanup; if preferred, there might be a new option which optionally performs this cleanup.Desktop