Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d8154cb

Browse filesBrowse files
authored
Merge pull request #9724 from jklymak/fixPDFbug
FIX: PDFpages bug
2 parents df1af2f + 621393b commit d8154cb
Copy full SHA for d8154cb

File tree

Expand file treeCollapse file tree

2 files changed

+16
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-1
lines changed

‎lib/matplotlib/backends/backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_pdf.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,8 @@ def print_pdf(self, filename, **kwargs):
25912591
bbox_inches_restore=_bbox_inches_restore)
25922592
self.figure.draw(renderer)
25932593
renderer.finalize()
2594-
file.finalize()
2594+
if not isinstance(filename, PdfPages):
2595+
file.finalize()
25952596
finally:
25962597
if isinstance(filename, PdfPages): # finish off this page
25972598
file.endStream()

‎lib/matplotlib/tests/test_backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pdf.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io
99
import os
10+
import sys
1011
import tempfile
1112

1213
import pytest
@@ -71,6 +72,19 @@ def test_multipage_pagecount():
7172
assert pdf.get_pagecount() == 2
7273

7374

75+
def test_multipage_properfinalize():
76+
pdfio = io.BytesIO()
77+
with PdfPages(pdfio) as pdf:
78+
for i in range(10):
79+
fig = plt.figure()
80+
ax = fig.add_subplot(111)
81+
ax.set_title('This is a long title')
82+
fig.savefig(pdf, format="pdf")
83+
pdfio.seek(0)
84+
assert sum(b'startxref' in line for line in pdfio) == 1
85+
assert sys.getsizeof(pdfio) < 40000
86+
87+
7488
def test_multipage_keep_empty():
7589
from matplotlib.backends.backend_pdf import PdfPages
7690
from tempfile import NamedTemporaryFile

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.