Applying PDF-printing-patch from Qt4.

Applying commit 08fc50d149745b078c9fd73a213c8c83307beaa2
"Headless and PDF printing fixes."

This commit though cuts out the headless stuff, which is obsolete by
now anyway. Moreover the commit added some functions that were never
used at all, I cut those out as well.