Skip to content

Commit

Permalink
Adding a .Root attribute in PdfWriter to allow setting its MediaBox o…
Browse files Browse the repository at this point in the history
…r Resources fields
  • Loading branch information
Cimon Lucas (LCM) authored and Cimon Lucas (LCM) committed Jul 20, 2020
1 parent 6c89216 commit b9a0e38
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pdfrw/pdfwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def __init__(self, fname=None, version='1.3', compress=False, **kwargs):
"on PdfWriter instance" % name)
setattr(self, name, value)

self.Root = None
self.pagearray = PdfArray()
self.killobj = {}

Expand Down Expand Up @@ -310,16 +311,14 @@ def _get_trailer(self):
self.make_canonical()

# Create the basic object structure of the PDF file
trailer = PdfDict(
Root=IndirectPdfDict(
Type=PdfName.Catalog,
Pages=IndirectPdfDict(
Type=PdfName.Pages,
Count=PdfObject(len(self.pagearray)),
Kids=self.pagearray
)
)
catalog_root = self.Root or IndirectPdfDict()
catalog_root.Type = PdfName.Catalog
catalog_root.Pages = IndirectPdfDict(
Type=PdfName.Pages,
Count=PdfObject(len(self.pagearray)),
Kids=self.pagearray
)
trailer = PdfDict(Root=catalog_root)
# Make all the pages point back to the page dictionary and
# ensure they are indirect references
pagedict = trailer.Root.Pages
Expand Down

0 comments on commit b9a0e38

Please sign in to comment.