This paper considers the problem of designing a multilevel pulse width modulated waveform (PWM) with a prescribed harmonic content. Multilevel PWM design plays a major role in many diverse engineering disciplines. In power electronics, multilevel PWM design corresponds to determining the inverter switching times and levels for selective harmonic elimination and harmonic compensation. In mechatronics, the same design corresponds to shaping input signals to damp residual vibrations in flexible structures. More generally, in most applications, the aim of PWM design is to minimize the total harmonic distortion while adhering to a prescribed harmonic content. The solution approach presented in this paper is based on linear programming with the objective of minimizing the total harmonic distortion. This objective is achieved within an arbitrarily small bound of the optimal solution. In addition, the linear programming formulation makes the design of such switching waveforms computationally tractable and efficient. Simulations are provided for corroboration.