The law is scheduled to take effect next year and will bar companies from leaving unsolicited Yellow Pages books on porches without the permission of the residence or business.
It's the first such ordinance in the nation.
The San Francisco Chronicle reports that Mayor Ed Lee quietly signed the ban into law on May 19 to cut the number of unwanted phone books being dropped into city neighborhoods.
David Chiu, president of the city's Board of Supervisors, said the ban was needed because the unsolicited books degraded the environment and blighted neighborhoods.
The Local Search Association, a commercial phone book industry trade group, has threatened to sue, saying the ban violates its members' rights.
Seattle passed an ordinance last year that created a registry that allows residents to opt-out of receiving the books. A federal judge this month upheld the ordinance after a challenge from publishers.