To generate those lines you need to run the complete simulation of the whole shot every frame, as if you'd just hit the cue ball. This requires keeping two copies of the table state - one for display and one for simulation. For each frame of the simulation you just store the position of each ball, and at the end use that data to draw lines with. This simulation wants to happen quickly enough to maintain an interactive frame rate, although you can work round spikes in compute time with a thread.
The physics for a basic 2D simulation aren't too complicated if you don't care too much about accurately simulating a real pool table. It gets significantly harder to simulate it well when you take in to account jump shots and swerve shots as the balls can then move along curves instead of straight lines. The shot where you break the pack is also difficult to simulate correctly as there are going to be lots of touching, or almost-touching balls, which may trip up a physics simulation.
I'd suggest trying out a few physics libraries to see which one gives you the best results. Setting up a box full of spheres and hitting one of them should be fairly simple in any decent physics engine.