A 3D printer with an automatic nozzle height positioning system can confirm whether the height of the nozzle meets the requirements of the printing height according to the height data measured by the displacement sensor, and realize the accurate positioning of the nozzle height to prevent the print adhesion or scraping.