anilgulecha/trelby — comment on commit 4c13588c576fb13022811265c7a6da31e72040bc
File: src/screenplay.py line 817
By oskusalerma:

This is the wrong way to do this. We don't want to make the core functionality more complex to support a niche utility found in Tools menu.

The right way to do this is to do the watermarking as a post-processing step.

Since we don't really want to implement PDF reading and modify the raw PDF contents, the right place to put the post-processing in is after we have a pml.Document and before we call pdf.generate on that. The post-processing can then iterate over pml.Document.pages and add/modify the pml operations on each page as it sees fit.

So:

1) Add generatePML function to screenplay, where all of the code from generatePDF goes to. It returns pager.doc.
2) All generatePDF does is:

return pdf.generate(self.generatePML(isExport))
3) The watermarking post-processing calls generatePML(True), post-processes the returned pml document to add watermarking, and calls pdf.generate itself.