As J_G told you, there are some libraries that can help you, just have
a look at php.net. But if you want to generate states (pictures, I
guess), may be you should take a look at XSL and its" transformations"
abilities. There are quite a lot of "pdf transformers" (some are even