Heralded generation of single photons in pure quantum states