We examine the electric-magnetic duality for a U(1) gauge theory on a general
4-manifold. The partition function for such a theory transforms as a modular
form of specific weight. However, in the canonical approach, we show that
S-duality, like T-duality, is generated by a canonical transformation leading
to a modular invariant partition function.Comment: latex, 10 page