PyPDF2:它可以更新数据流吗? [英] PyPDF2: can it update data stream?

查看:27
本文介绍了PyPDF2:它可以更新数据流吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将多边形注释转换为 pdf 并修改其形状.我现在可以通过将 pdf 和空白 pdf 与仅多边形合并来做到这一点,然后我可以更新顶点和矩形.

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.

然而,打开新pdf时多边形形状仍然看起来是旧的,即使在形状上点击几下后它会刷新.我需要修复这个问题,发现这可能是由注释对象中的数据流引起的,它似乎仍然包含旧的多边形形状.但是在保存新的 pdf 之前,我无法弄清楚如何覆盖它.我使用类似下面的代码来更新顶点和矩形,但无法弄清楚如何更新数据流.

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))])})

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

请查看链接中的图片

我希望得到任何信息.

推荐答案

如果有人遇到类似问题,只想分享我的解决方案 --

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')

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

没有那个幽灵形状,注释多边形显示正确!不知道为什么使用 '/AP' 对象.但看起来没问题.

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

这篇关于PyPDF2:它可以更新数据流吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆