How do I recover deleted books from inventory in minecraft? [duplicate]
Your only chance would be to Alt + F4 out of the game (or crash it by other means) before it saves anything to your drive, so you have to do this as soon as possible. But you should use this approach with caution. In rare cases it could as well corrupt your game files and eventually destroy your saved world.
If it's already too late for that there is no known way of getting your books back. There is currently nothing in the game that can restore a cleared inventory by normal means.
For the future:
Make backups. Save a copy of your world somewhere else and doing so on a regular basis can save you a lot of headache.