matplotlib/matplotlib — pull request #2453 by megies (2013-09-23 18:59:22+00:00)
Title: PdfPages: add option to delete empty file when closed

I have automatic signal processing scripts with nested loops that output plots in multipage pdfs.
Sometimes, though, these loops do not produce a single pdf page and I ended up with loads of broken/empty pdf files. I found it useful to be able to tell the `PdfPage` object at initialization (using `with` statement) that it should go straight to trash if it ends up empty.

I wasn't sure if this was to be considered too special to go into the main repo but I figured opening a PR can't hurt too much. Also, the current behavior (keep empty pdf files)

- PdfPages objects can be told at initialization to delete the pdf file
when closed, if no page was actually plotted
- keep the default to not delete empty pdf files so current behavior is
not changed
- also some basic tests for it