 Zhang Wenwei passed the imperial examinations in the "Jinshi" class in 875, during the reign of Emperor Xizong.He thereafter served as a surveyor for the office of salt and iron monopolies; he then served as a sheriff of a county near the imperial capital Chang'an, as well as a scholar at an imperial institute.After his father Zhang Shang died in 877, he left governmental service to observe a mourning period and to attend to the household.