I was searching for some more information about canonical transformations. Thus consider canonical coordinates $(p_i,q_i)$ and an other set of canonical coordinates $(P_i, Q_i)$. Both sets will satisfy, $$ \delta \int_{t_1}^{t_2}(P_i\dot{Q_i}-K(P_i, Q_i,t)) dt = 0,$$ where $K$ is the corresponding Hamiltonian, and, $$ \delta \int_{t_1}^{t_2}(p_i\dot{q_i}-H(p_i, q_i,t)) dt = 0,$$ where $H$ is the corresponding Hamiltonian. Now all of the books I have found use the fact that if there is added a total derivative then the integral will not be changed since Hamiltonian's principle has zero variation at the end points. By this a relation of the following form is meant, $$ \lambda(p_i\dot{q_i}-H) = P_i\dot{Q_i}-K +\frac{dF}{dt},$$ where $\lambda$ is a scaling parameter that later will be set $1$ or was directly ommitted.
The question is was considering is the following: Are there cases where there doesn't exist such a total derivative to link both set of coordinates? More general does there always exist a transformation and how would one show this?
Could someone give me an answer or guide me to a reference where this question is treated?