The Acrobat SDK is a tool for automating Acrobat. A plug-in can get this info (or something like it, far more complex than "foreground and background colours", detailed knowledge of PDF internals a must. Text does not have a specific background associated with it, full analysis of all the preceding graphical content is needed, perhaps with transparency blending, to figure out the background in effect for a piece of text; fabulously complicated. There are 11 different colour spaces including CMYK and separation, a file can even have text painted in a pattern.)
But Acrobat is not for server use and has no Linux version,
Adobe's PDF Library provides a C/C++ interface to a similar API, and can be licensed by platform, including some Linux installs (with royalties, price by negotation but think five figures).