Pain management

I've been prescribed tramadol for pain as needed. I was also told to use stool softener, I'm taking the maximum daily allowance of the stool softener and I'm still have problems with constipation. I'm also experiencing gas and heartburn when I'm on the tramadol.

Does anyone have any recommendations or tips.