flyingsaucerproject / flyingsaucer

XML/XHTML and CSS 2.1 renderer in pure Java
Other
2.02k stars 564 forks source link

Support PDF digital signature #305

Open Sobot opened 7 months ago

Sobot commented 7 months ago

Any chance of including the support for PDF digital signature? If you think this makes sense I could contribute with a pull request

https://helpx.adobe.com/acrobat/using/signing-pdfs.html

I would prepare a pull request for this that would implement a org.xhtmlrenderer.simple.PDFSigner similar as org.xhtmlrenderer.simple.PDFRenderer

That would encapsulate https://api.itextpdf.com/iText5/java/5.5.13.3/com/itextpdf/text/pdf/security/MakeSignature.html

Or would you suggest a better aproach?

asolntsev commented 7 months ago

@Sobot Hi. Thanks for the suggestion. Well, may be. :) I don't see any reasons why we should not do it. But I also don't see why it's needed. Isn't it so that usually a "system" (like internet-bank) generates the PDF, and user should sign it?

Sobot commented 7 months ago

Hi @asolntsev thank you for the reply.

I have a case where I need to generate digitally signed pdf to discourage users from editing them after downloading. And also verify that the pdf is generated by a trusted source.

Wanted to check if you think you think it would be possible do have alterative aproach by extending org.xhtmlrenderer.pdf.ITextRenderer or use it a a reference to a document to sign so I can leverage org.xhtmlrenderer.pdf.PDFCreationListener#onClose to autosign all documents?

pbrant commented 7 months ago

@Sobot Using PDFCreationListener is the approach I'd recommend (and the approach we've taken in the past at work).

This does assume that you can use an invisible signature or at least can place the signature at a known, static location though.

andreasrosdal commented 2 months ago

https://github.com/esig/dss - you can use this DSS (Digital Signature Service) to sign PDF files, even PDF files created by FlyingSaucer can be used as input.