Sorry for bother you, Kovid. I was able to find a way to employ custom margins with Calibre Viewer in paged mode. In fact, I could find TWO ways, but the last one has an inconvenience that, so far, I was not able to fix.
If you open MarginsTestCase-ONE with Calibre Viewer, you'll see that your program can display pages without issues, in spite of the epub has custom margins, modified by a script. To get that, I enclosed all the content in a div wrapper and I applied margins to it. Probably, this is the most economic way to get custom margins with Calibre Viewer.
Now, if you open MarginsTestCase-TWO, you'll see a totally different script to apply custom margins. This script takes into account, the current values managed for Viewer for width, column-width and column-gap. And it calculates the new margins according to those previous values. And it works fine, except for the last paragraph of any .xhtml file.



Evidently I need to modify another more parameter of the Viewer to fix that, but I couldn't locate it in your layout() function. Could you tell me, according to your experience and since you are the creator and the developer of Calibre, what do you think I have to modify, to fix that bleeding of the last pages? Thank you very much in advance.