如何知道在使用reportlab渲染pdf期间放置了哪个页码flowable [英] How to know on what page number flowable was placed during rendering a pdf with reportlab

查看:38
本文介绍了如何知道在使用reportlab渲染pdf期间放置了哪个页码flowable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定在渲染为 pdf 后每个页面(需要页码)将是可流动的.我想为flowable添加一个自定义id属性,所以我会知道它是什么flowable.但是我如何确定它将放置在哪个页面上?实现这一目标的最佳方法是什么?

How to determine on what page(need a page number) will be each flowable after rendering to pdf. I was thinking to add a custom id attribute to flowable, so i will know what flowable is it. But how can i determine on what page it will be placed? What is the best way to achieve this?

推荐答案

我以以下解决方案结束.添加了一个自定义 id flo_id 到每个 flowable.并覆盖BaseDocTemplate中的handle_flowable方法,在那里检查和保存id,

I ended with following solution. Addeda an custom id flo_id to every flowable. And override method handle_flowable in BaseDocTemplate, where was checking and saving id,

class SignDocTemplate(BaseDocTemplate):
   blocks_to_pages = {}
   def handle_flowable(self, flowables):
     f = flowables[0]
     BaseDocTemplate.handle_flowable(self, flowables)
     if hasattr(f,'flo_id'):
       if self.blocks_to_pages.has_key(self.canv._pageNumber):
          self.blocks_to_pages[self.canv._pageNumber].append(f.flo_id)
       else:
          self.blocks_to_pages[self.canv._pageNumber]= [f.flo_id,]

构建文档后,它将在 blocks_to_pages 变量中的文档实例中可用.

And after building a doc it will be available at document instance in blocks_to_pages variable.

这篇关于如何知道在使用reportlab渲染pdf期间放置了哪个页码flowable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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