Skip to content

Commit b9a0e38

Browse files
Cimon Lucas (LCM)Cimon Lucas (LCM)
authored andcommitted
Adding a .Root attribute in PdfWriter to allow setting its MediaBox or Resources fields
1 parent 6c89216 commit b9a0e38

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

pdfrw/pdfwriter.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def __init__(self, fname=None, version='1.3', compress=False, **kwargs):
262262
"on PdfWriter instance" % name)
263263
setattr(self, name, value)
264264

265+
self.Root = None
265266
self.pagearray = PdfArray()
266267
self.killobj = {}
267268

@@ -310,16 +311,14 @@ def _get_trailer(self):
310311
self.make_canonical()
311312

312313
# Create the basic object structure of the PDF file
313-
trailer = PdfDict(
314-
Root=IndirectPdfDict(
315-
Type=PdfName.Catalog,
316-
Pages=IndirectPdfDict(
317-
Type=PdfName.Pages,
318-
Count=PdfObject(len(self.pagearray)),
319-
Kids=self.pagearray
320-
)
321-
)
314+
catalog_root = self.Root or IndirectPdfDict()
315+
catalog_root.Type = PdfName.Catalog
316+
catalog_root.Pages = IndirectPdfDict(
317+
Type=PdfName.Pages,
318+
Count=PdfObject(len(self.pagearray)),
319+
Kids=self.pagearray
322320
)
321+
trailer = PdfDict(Root=catalog_root)
323322
# Make all the pages point back to the page dictionary and
324323
# ensure they are indirect references
325324
pagedict = trailer.Root.Pages

0 commit comments

Comments
 (0)