Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change PdfPages to default to keep_empty=False and eventually deprecate keep_empty #11771

Closed
@anntzer

Description

@anntzer

PdfPages has an option, keep_empty, that sets whether a PdfPages object with zero figures is written to the disk at all or not. This was introduced in #2453; previously PdfPages behaved as if keep_empty=True (and this was left the default to maintain backcompat).

In fact, a pdf file with zero pages is simply not a valid pdf document. See e.g. the pdf standard (https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf) p. 33: "A PDF document consists of a collection of objects that together describe the appearance of one or more pages..." (emphasis mine). Or one can simply check that the empty file created by PdfPages("/tmp/foo.pdf").close() is indeed deemed invalid (error-on-open) by at least Acrobat, mupdf, and xpdf.

Thus I propose to eventually stop generating such invalid files at all via switching the default value to keep_empty=False and eventually killing the kwarg (deprecation strategy TBD, perhaps warn (with a suppress_warning kwarg) if such a file would have been created, yada yada).

(Apparently multipage support in mplcairo is getting used, and cairo cannot generate zero-page pdfs, so that's how I found out about this...)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions