The formation of absorption lines in solar spectrum It is said that absorption lines originate from regions higher in the photosphere where the gas is cooler. 

The gas should be absorbing photons, then re-emitting them... absorb, re-emit, absorb, re-emit...

My question is where are the photons produced by re-emission? Why are there absorption lines? 

Although photons could be scattered, photons at other places could be scattered to our line our sight. Surely the total number of photons does not drop the further out you go? So while photons originally headed in the direction of an observer are possibly absorbed and re-emitted in a direction away from the observer, surely this will be made up for by a photon being emitted from another location in the direction of the observer? Otherwise wouldn't there be a location somewhere else where a bunch of extra scattered photons can be observed? 

If we integrate all the photons at the lower surface of the photosphere A and integrated all the photons at the upper surface of the chromosphere C, surely there are the same number of photons? Otherwise, where have they gone? Where is the lost energy?

Are there less photons emitted from the surface C because some have been emitted back down into the Sun? But that has to reach an equilibrium, or there would be a cascading increase in the number of photons inside the sun.
In the upper photosphere, the electrons join with the ions to neutralize the atom. When a photon strikes this atom (the atom absorbs the photon), it promotes a electron from a low energy shell to an higher energy shell. The electron then falls back to the lower energy shell emitting a photon in a different direction. When you break the sunlight into wavelengths (by a prism), you will see dark bands where the light was absorbed by the atoms and emitted in a different direction. These bands correspond to the energy absorbed and released when an electron changes energy shells. Here is the sun's light spread out to show the absorption bands. 

Added: Here is a high resolution of the wavelengths from the sun.

Apr 20: You have the wrong interpretation of Figure 16.9. At level A, there is about the same number of photons at all wavelengths coming at the observer on Earth. As the photons pass through the Chromosphere, the photons with the wavelengths of the atom's electron transition are absorbed and redirected away from the observer. The photons with different wavelengths of the atom's electron transition eventually arrive at the observer. This is why there are dark lines in the spectrum. It is because most of the photons are absorbed and redirected in a different direction. 

The absorption lines are formed at a higher region since the photons are removed from the spectrum.