Search code examples
javapdfcertificatepdfboxsignature

Java: Signing a PDF with an existig pfx-certificate


I guess my question is rather simple. All I found in my research were threads with very short answers sounding like "DAT SO EZ LUK HEER NAP: link".. I tried those links and they were all 404.. So I'm exposing myself to another public execution and will try this thread a millionth time.

I'm working with PDFBox 2.0.17 and I am trying to sign a PDF-File with an already existing pfx-certificate. Thats pretty much everything. I got some pretty disgusting solutions myself with printing the file via pdf-Creator and stuff, but there must be a smoother, nicer solution.

I'd be pretty thankful for every non-404-Link and will accept any kind of public humiliation.

Best regards, YXCD

P.S.: Of course I found solutions like PDFone and other providers. But I'm trying to do this without getting myself bankrupt ..


Solution

  • Okay, to sum this up..

    My experience here is that PDFBox has some very precise dependencies which will throw Exceptions the moment they are slightly out of version. I fixed every problem by first of all reloading the entire PDFBox-Files and then downloading every dependencies the exact version as listed in the PDFBox Version. Using newer versions will throw exceptions.

    At the end I took the CreateSignature-Example and rewrote it for my needs. Then it all worked perfectly and smoothly.

    Thanks to @mkl and @TilmanHausherr for your comments and giving me the right guidelines.