Is there any way to create .pfx files in order to sign documents, I've found a program called x509 Certificate Generate,but I want to know if it can be generated in code using c#.
There is a Microsoft command-line tool makecert that can be used to generate certificates. It's part of the Windows SDK. On my machine there are half a dozen versions e.g. in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64
. Then in your code you can start a process to run the executable with the appropriate parameters.