pdf downloading logic