Story Thieves by James Whitcomb Riley

A practical, puzzle-minded middle-schooler discovers his classmate can slip into books and pull fictional characters into the real world; when a dangerous theft upends both worlds, the two team up for a fast-paced adventure that blurs the line between fiction and reality and forces them to outwit a threat that could destroy stories and ordinary life alike.