According to this page, one of the basic director duties is to make decisions for the benefit of the company, not yourself. How does it work when a director is also a shareholder and decides to pay a dividend? Obviously he is acting for his own benefit.
The word "company" (like "companions") refers to people who "come together" (or associate—hence memorandum/articles of association) for a common purpose. In other words, a company is its members.
Thus a director's duty to act in the best interests of the "company" simply means that he must act in its members' best interests (as opposed to his own, or anyone else's).
A limited company is the same, only the members' liability for acts that are undertaken toward the common purpose is limited by law (in the case of companies limited by shares, the members are called "shareholders" and their liability is limited to any amounts unpaid on their called-up share capital). Sure, we have created the fiction that such companies are incorporeal "people" capable of owning property and contracting in their own name; and we have developed legislation to protect third parties from abuse… but nonetheless a director's duties toward the company still refers to his duties towards its members.
Therefore the dichotemy that you highlight in your question is easily resolved by understanding that the duty on a director who is also a shareholder is only to ensure that decisions are in the interests of all shareholders.
Decisions to pay dividends cannot normally constitute a breach of this duty because, by definition, they're paid to all shareholders (unless there are multiple classes of share); contrast with a decision to pay a director's bonus. However, if the director decided to declare a dividend solely because he personally needed some cash and in doing so the business is put at risk, it could be argued that he has breached his fiduciary duty to safeguard the interests of all shareholders.
That said, decisions to pay dividends are usually approved by the shareholders in general meeting—in which case the decision is effectively taken by the members themselves rather than the directors. It could still be argued that merely recommending a dividend in circumstances such as those above could constitute a breach of duty, but I think that's probably going beyond the scope of this question.
As you said, the director should make decision for the benefit of the company, not himself.
So he shouldn't have in mind the fact that he's a shareholder when deciding things.
And if a decision made by him looks like he could have taken advantage of his position in order to benefit himself, he should expose in a transparent way all the reasons he had to take the decision he made.