Context. Galactic cosmic rays (CRs) play a crucial role in ionisation, dissociation, and excitation processes within dense cloud regions where UV radiation is absorbed by dust grains and gas species. CRs regulate the abundance of ions and radicals, leading to the formation of more and more complex molecular species, and determine the charge distribution on dust grains. A quantitative analysis of these effects is essential for understanding the dynamical and chemical evolution of star-forming regions. Aims. The CR-induced photon flux has a significant impact on the evolution of the dense molecular medium in its gas and dust components. This study evaluates the flux of UV photons generated by CRs to calculate the photon-induced dissociation and ionisation rates of a vast number of atomic and molecular species, as well as the integrated UV photon flux. Methods. To achieve these goals, we took advantage of recent developments in the determination of the spectra of secondary electrons, in the calculation of state-resolved excitation cross sections of H2 by electron impact, and of photodissociation and photoionisation cross sections. Results. We calculated the H2 level population of each rovibrational level of the X, B, C, B′, D, B″, D′, and a states. We then computed the UV photon spectrum of H2 in its line and continuum components between 72 and 700 nm, with unprecedented accuracy, as a function of the CR spectrum incident on a molecular cloud, the H2 column density, the isomeric H2 composition, and the dust properties. The resulting photodissociation and photoionisation rates are, on average, lower than previous determinations by a factor of about 2, with deviations of up to a factor of 5 for the photodissociation of species such as AlH, C2H2, C2H3, C3H3, LiH, N2, NaCl, NaH, O2+, S2, SiH, l-C4, and l-C5H. A special focus is given to the photoionisation rates of H2, HF, and N2, as well as to the photodissociation of H2, which we find to be orders of magnitude higher than previous estimates. We give parameterisations for both the photorates and the integrated UV photon flux as a function of the CR ionisation rate, which implicitly depends on the H2 column density, as well as the dust properties.