Beampattern synthesis seeks to optimize array weights to shape radiation patterns, playing a critical role in various wireless applications. In addition to theoretical advancements, recent hardware innovations have facilitated new avenues to enhance beampattern synthesis performance. This paper studies the beampattern synthesis problem using newly proposed electromagnetically reconfigurable antennas (ERAs). By utilizing spherical harmonics decomposition, we simultaneously optimize each antenna's radiation pattern and phase shift to match a desired beampattern of the entire array. The problem is formulated for both far-field and near-field scenarios, with the optimization solved using Riemannian manifold techniques. The simulation results validate the effectiveness of the proposed solution and illustrate that ERAs exhibit superior beampattern synthesis capabilities compared to conventional fixed radiation pattern antennas. This advantage becomes increasingly significant as the array size grows.