PyPDF2: can it update data stream?

给你一囗甜甜゛ 提交于 2019-12-08 07:47:02

问题


I need to get a polygon comment into a pdf and revise it's shape. I'm able to do so now by merging the pdf and a blank pdf with just the polygon, then I am able to update the vertices and the rect.

However, the polygon shape still looks the old one when opening the new pdf, even though it will be refreshed after a few clicks on the shape. I need to have this fixed and found this is probably caused by the data stream in the annotation object, which seems to still contain the old polygon shape. But I cannot figure out how to overwrite that before saving the new pdf. I used code similar below to update the vertices and rect, but cannot figure out how to update the data stream.

annot.getObject().update({NameObject('/Rect'):ArrayObject([FloatObject(min(xcoords)), FloatObject(min(ycoords)), FloatObject(max(xcoords)), FloatObject(max(ycoords))])})

Please see image in link

I would appreciate any information.


回答1:


In case someone has a similar problem, just wanted to share my solution --

I don't find a way to update the stream data, however, I am able to get rid of the "ghost" shape by completely removing that object within the annotation object.

annot.getObject().pop('/AP')

Without that ghost shape, the annotation polygon displays properly! Not sure why the use of '/AP' object though. But it looks alright.



来源:https://stackoverflow.com/questions/50142232/pypdf2-can-it-update-data-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!