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

查看:121
本文介绍了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天全站免登陆