Reduce the use of XObjects in pdf backend [backport to 1.4.x]

Fixes #3345, fixes #2910. Fixes the pdf part of #2247, and it seems to me that the svg part is already fixed on master.