Interface and surface stabilization of the polarization in ferroelectric thin films