User Activity

I have an MP560. I want to write my own standalone php/Java  program that writes to my printer to create formatted labels on a sheet.  What is the API to build the print data, eg Escape sequences or other codes?