How to find out what page number was loaded during pdf rendering with reportlab

How to determine which page (page number is needed) will each stream after rendering in pdf. I was thinking of adding a user id attribute to the current one, so I will know that it is fluid. But how can I determine which page it will be placed on? What is the best way to achieve this?

+2
source share
2 answers

I ended up with the following solution. Added custom id flo_id for each thread. And override the handle_flowable method in BaseDocTemplate, where the id was checked and stored,

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,] 

And after creating the document, it will be available in the document instance in the variable blocks_to_pages.

0
source

At what point do you need this information? It becomes available as the document is created, so you can get it after rendering using overriding methods like afterPage , afterDrawPage and afterFlowable . Then you can get the page number from the DocTemplate class (I believe the class variable is called something like _currentPage , but you need to check the ReportLab code, since I don't think this is documented).

+2
source

All Articles