The ionization fraction plays a key role in the chemistry and dynamics of molecular clouds. We study the H13CO+, DCO+ and HOC+ line emission towards the Horsehead, from the shielded core to the UV irradiated cloud edge, i.e., the Photodissociation Region (PDR), as a template to investigate the ionization fraction gradient in molecular clouds. We analyze a PdBI map of the H13CO+ J=1-0 line, complemented with IRAM-30m H13CO+ and DCO+ higher-J line maps and new HOC+ and CO+ observations. We compare self-consistently the observed spatial distribution and line intensities with detailed depth-dependent predictions of a PDR model coupled with a nonlocal radiative transfer calculation. The chemical network includes deuterated species, 13C fractionation reactions and HCO+/HOC+ isomerization reactions. The role of neutral and charged PAHs in the cloud chemistry and ionization balance is investigated. The detection of HOC+ reactive ion towards the Horsehead PDR proves the high ionization fraction of the outer UV irradiated regions, where we derive a low [HCO+]/[HOC+]~75-200 abundance ratio. In the absence of PAHs, we reproduce the observations with gas-phase metal abundances, [Fe+Mg+...], lower than 4x10(-9) (with respect to H) and a cosmic-rays ionization rate of zeta=(5+/-3)x10(-17) s(-1). The inclusion of PAHs modifies the ionization fraction gradient and increases the required metal abundance. The ionization fraction in the Horsehead edge follows a steep gradient, with a scale length of ~0.05 pc (or ~25), from [e-]~10(-4) (or n_e ~ 1-5 cm(-3)) in the PDR to a few times ~10(-9) in the core. PAH^- anions play a role in the charge balance of the cold and neutral gas if substantial amounts of free PAHs are present ([PAH] >10(-8)).