You have to know the type of data being passed. Without that information you can't do anything useful.
If you know that the data represents some kind of file type you can try to detect the type. With Linux there is the
file
command that uses the
magic(5): file command's magic pattern file - Linux man page[
^] to detect file types. With Windows you have to implement something similar (or search the web for existing implementations).
Once you identified the type you can save the data as file with the appropriate extension and use a type specific converter to create a PDF file.
PDF files for example begin with the string "%PDF-". If your data begins with these characters you can assume that it is a PDF file and can be stored as such.