On the Cramér transform, large deviations in boundary value problems, and the conditional invariance principle