We investigate the production of a quark-antiquark pair in diffractive photon-proton scattering, approximating soft pomeron exchange by the exchange of two nonperturbative gluons. In deep inelastic scattering at HERA, events with two jets and the scattered proton in the final state are predicted to be observable, with an important contribution from charm production. For photoproduction of light quark jets with high transverse momentum we find that both exchanged gluons must have a large invariant mass, so that the cross section is very small, whereas for charm quarks it is quite appreciable. From our calculation we also extract the quark structure function of the pomeron for the scaling variable z no too close to 0 or 1, finding a strong flavour dependence and a behaviour somewhat harder than z(1 - z) for light quarks.