The story
It first served as a way of swearing something was true. In 1833, a London newspaper quoted a speaker exclaiming, “By the book, it’s myself is the moral o’ patience!” The rule-following sense showed up soon after, in Edgar Allan Poe’s 1845 story The Murders in the Rue Morgue, where good card play means proceeding by “the book.”