Using the Laplace transform

$$ sU(x,s)=4U_{xx}(x,s)+2\cos(2x)+5\cos(3x),\ \ U_x(0,s)=U_x(\pi,s)=0 $$

Solving for $x$ we have

$$ U(x,s) = \frac{2}{s}-\frac{\cos (2 x)}{s+16}+\frac{5 \cos (3 x)}{s+36} $$

and after inversion

$$ u(x,t) = 2-e^{-16 t} \cos (2 x)+5 e^{-36 t} \cos (3 x) $$