Hi Ulf, I tried it with other PDF files and they run fine. The exception is caused by not adding "%%EOF" to the trailer, which I don't know how to do it. anyway thanks, I switched to use SecurSign to encrypt my PDFs instead. Can you possibly take a look what is wrong with my code in another thread?