In this work, a feedforward dynamic controller is devised in order to achieve $H_2$-optimal rejection of signals known with finite preview, in discrete-time systems. The feedforward approach requires plant stability and, more generally, robustness with respect to parameter uncertainties. On standard assumptions, those properties can be guaranteed by output dynamic feedback, while dynamic feedforward is specifically aimed at taking advantage of the available preview of the signals to be rejected, in compliance with a two-degree-of-freedom control structure. The geometric constraints which prevent achievement of perfect rejection are first discussed. Then, the procedure for the design of the feedforward dynamic compensator is presented. Since the approach proposed in this work is based on spectral factorization via Riccati equation of a real rational matrix function directly related to the original to-be-controlled system, the delays introduced to model the preview of the signals to be rejected do not affect the computational burden intrinsic in the solution of the appropriate algebraic Riccati equation. A numerical example helps to illustrate the geometric constraints and the procedure for the design of the feedforward dynamic unit.