In this paper, we discuss four different optimization problems for distributed antenna systems (DAS) with and without D2D communication, respectively. The first and the third problems are maximizing spectral efficiency (SE) and energy efficiency (EE) of the DAS with D2D communication on the conditions of the minimum SE of DAS as well as D2D pair, the maximum transmit power of each remote access unit (RAU) and maximum transmit power of D2D transmitter. The second and the forth problems are maximizing SE of the DAS on the conditions of the minimum SE as well as the maximum transmit power of RAUs. We exploit the sub-gradient iteration method to obtain the optimal power allocation and summarize optimal power allocation algorithms for the first and second problems. We exploit fractional programming method to investigate the third and fourth problems and develop corresponding optimal power allocation algorithms. Simulation results demonstrate the effectiveness of the proposed power allocation algorithms and show the SE and EE of the DAS by using D2D communication are much better than DAS without D2D communication.