5. As shown in Figure 2, with the sides $AB$ and $AD$ of the square $ABCD$ as diameters, semicircles are drawn outside the square. A line is drawn through $A$ intersecting the two semicircles at $E$ and $F$. If the area of the square $ABCD$ is $1997$, and $AE$ and $AF$ are integers, then the length of $EF$ is ( ).
(A) 63
(B) 62
(C) 61
(D) 59
5.A.

Connect $B E, D F$, then $\angle B E A=\angle A F D=90^{\circ}$.
Also, $\angle E B A+\angle E A B=90^{\circ}, \angle E A B+\angle F A D=90^{\circ}$, hence $\angle E B A=\angle F A D$.
Since $A B=A D$, thus,
$\triangle B E A \cong \triangle A F D, D F=A E$.
Let $A E=x, A F=y$, then
$x^{2}+y^{2}=A D^{2}=1997$ (where $x, y$ are positive integers).
Obviously, $x, y$ must be one odd and one even. Without loss of generality, let $x$ be odd and $y$ be even, then the last digit of $x$ can only be 1 or 9, and the last digit of $y$ can be 4 or 6.
Since $1997<45^{2}$, hence $x$ does not exceed 39, and $y$ does not exceed 44.
Upon inspection, only when $x=29, y=34$, the equation $x^{2}+y^{2}=1997$ holds. Therefore, $E F=x+y=63$.