diff --git a/pdfrw/pdfwriter.py b/pdfrw/pdfwriter.py index 3c887ba..4641af3 100755 --- a/pdfrw/pdfwriter.py +++ b/pdfrw/pdfwriter.py @@ -262,6 +262,7 @@ def __init__(self, fname=None, version='1.3', compress=False, **kwargs): "on PdfWriter instance" % name) setattr(self, name, value) + self.Pages = None self.pagearray = PdfArray() self.killobj = {} @@ -310,14 +311,14 @@ def _get_trailer(self): self.make_canonical() # Create the basic object structure of the PDF file + pages = self.Pages or IndirectPdfDict() + pages.Type = PdfName.Pages, + pages.Count = PdfObject(len(self.pagearray)), + pages.Kids = self.pagearray trailer = PdfDict( Root=IndirectPdfDict( Type=PdfName.Catalog, - Pages=IndirectPdfDict( - Type=PdfName.Pages, - Count=PdfObject(len(self.pagearray)), - Kids=self.pagearray - ) + Pages=pages, ) ) # Make all the pages point back to the page dictionary and