  The photon PDF of the proton is needed for precision comparisons of LHC cross
sections with theoretical predictions. In a recent paper, we showed how the
photon PDF could be determined in terms of the electromagnetic proton structure
functions $F_2$ and $F_L$ measured in electron-proton scattering experiments,
and gave an explicit formula for the PDF including all terms up to
next-to-leading order. In this paper we give details of the derivation. We
obtain the photon PDF using the factorisation theorem and applying it to
suitable BSM hard scattering processes. We also obtain the same PDF in a
process-independent manner using the usual definition of PDFs in terms of
light-cone Fourier transforms of products of operators. We show how our method
gives an exact representation for the photon PDF in terms of $F_2$ and $F_L$,
valid to all orders in QED and QCD, and including all non-perturbative
corrections. This representation is then used to give an explicit formula for
the photon PDF to one order higher than our previous result. We also generalise
our results to obtain formul\ae\ for the polarised photon PDF, as well as the
photon TMDPDF. Using our formula, we derive the $P_{\gamma i}$ subset of DGLAP
splitting functions to order $\alpha \alpha_s$ and $\alpha^2$, which agree with
known results. We give a detailed explanation of the approach that we follow to
determine a photon PDF and its uncertainty within the above framework.
