-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
is-featureA feature requestA feature requestworkflow-mergeFrom a users perspective, merging is the affected feature/workflowFrom a users perspective, merging is the affected feature/workflow
Description
I'm using pdfly
to create a book from single-page pdf file. Link on the right side does not work.
I've nailed it down. When attributes are merged /Rect
is not translated. I made a workaround in my own script:
...
page = reader.pages[first]
other = reader.pages[second]
tx = float(page.mediabox.width)
other[NameObject(PG.ANNOTS)] = ArrayObject(
list(
_transform_annots(get_annotations(other), tx=tx)
)
)
page.merge_translated_page(
other, tx=tx, ty=0, expand=True,
)
writer.add_page(page)
def _transform_annots(annots, tx):
for annot in annots:
obj = annot.get_object()
#obj = copy.deepcopy(obj)
if '/Rect' in obj:
rect = obj['/Rect']
obj[NameObject('/Rect')] = ArrayObject([
FloatObject(rect[0] + tx),
rect[1],
FloatObject(rect[2] + tx),
rect[3],
])
yield annot
def get_annotations(page):
if PG.ANNOTS in page:
annots = page[PG.ANNOTS]
if isinstance(annots, ArrayObject):
return annots
return []
I'd like to have this fixed in upstream version of pypdf
. I tried to do it myself and ran into a problem. I can translate existing indirect object (as in code above). But it should be copied since attribute is mutated. And I'm not sure how to do it.
Metadata
Metadata
Assignees
Labels
is-featureA feature requestA feature requestworkflow-mergeFrom a users perspective, merging is the affected feature/workflowFrom a users perspective, merging is the affected feature/workflow