It is also important to plant them at the same depth they were growing. They don't do well when planted any deeper. Pansies are cool season annuals. As the summer gets warm, their blooming slows down. You can also try cutting them back to within a few inches of the ground when it gets too hot and they may fill back out and begin blooming again in fall.
Pansies also profit from regular feeding with a water-soluble fertilizer high in phosphorus.
To keep pansies compact, be sure they receive strong light and stay well fertilized. This last few years, there seems to be a lot of pansies available in fall. Pansies do very well in fall, often blooming right up until the snow covers them up. As a bonus, you may even have a few of them winter in protected locations or during mild winters. The requirements for pansies and violas are the same.