In this paper we examine how the predictions of conformal invariance can be widely exploited to overcome the difficulties of the density-matrix renormalization group near quantum critical points. The main idea is to match the set of low-lying energy levels of the lattice Hamiltonian, as a function of the systems size, with the spectrum expected for a given conformal field theory in two dimensions. As in previous studies this procedure requires an accurate targeting of various excited states. Here we discuss how this can be achieved within the DMRG algorithm by means of the recently proposed Thick-restart Lanczos method. As a nontrivial benchmark we use an anisotropic spin-1 Hamiltonian with special attention to the transitions from the Haldane phase. Nonetheless, we think that this procedure could be generally valid in the study of quantum critical phenomena.