  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. 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 is intended to evaluate 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. Our study takes advantage of recent developments in the
determination of the spectra of secondary electrons, in the calculation of
state-resolved excitation cross sections of H$_2$ by electron impact, and of
photodissociation and photoionisation cross sections. We calculate the H$_2$
level population of each rovibrational level of the $X$, $B$, $C$, $B'$, $D$,
$B''$, $D'$ and $a$ states. We then compute the UV photon spectrum of H$_2$ 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
H$_2$ column density, the isomeric H$_2$ composition, and the dust properties.
The resulting photodissociation and photoionisation rates are, on average,
smaller than previous determinations by a factor of about 2, with deviations up
to a factor of 5. A special focus is given to the photoionisation rates of
H$_2$, HF, and H$_2$, as well as to the photodissociation of H$_2$, which we
find to be orders of magnitude higher than previous estimates.
