PHP can write binary files just as easily as it can write text files (easier, in fact, if you think about character encoding issues). That said, a PDF file can be written entirely in 7-bit ASCII.
You will of course need to know how the PDF format works. I don't have the relevant references on me right now, but Adobe does provide the specification in their documentation library (http://www.adobe.com/devnet/pdf.html).