Class: Decidim::Initiatives::PdfSignatureExample
- Inherits:
-
Object
- Object
- Decidim::Initiatives::PdfSignatureExample
- Defined in:
- decidim-initiatives/app/services/decidim/initiatives/pdf_signature_example.rb
Overview
Example of service to add a signature to a pdf
Instance Attribute Summary collapse
-
#pdf ⇒ Object
Returns the value of attribute pdf.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ PdfSignatureExample
constructor
Public: Initializes the service.
-
#signed_pdf ⇒ Object
Public: PDF signed using a new certificate generated by the service.
Constructor Details
#initialize(args = {}) ⇒ PdfSignatureExample
Public: Initializes the service. pdf - The pdf document to be signed
15 16 17 |
# File 'decidim-initiatives/app/services/decidim/initiatives/pdf_signature_example.rb', line 15 def initialize(args = {}) @pdf = args.fetch(:pdf) end |
Instance Attribute Details
#pdf ⇒ Object
Returns the value of attribute pdf.
11 12 13 |
# File 'decidim-initiatives/app/services/decidim/initiatives/pdf_signature_example.rb', line 11 def pdf @pdf end |
Instance Method Details
#signed_pdf ⇒ Object
Public: PDF signed using a new certificate generated by the service
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'decidim-initiatives/app/services/decidim/initiatives/pdf_signature_example.rb', line 20 def signed_pdf @signed_pdf ||= StringIO.open(pdf) do |stream| parsed_pdf = Origami::PDF.read(stream) parsed_pdf.append_page do |page| page.add_annotation(signature_annotation) parsed_pdf.sign( certificate, key, method: "adbe.pkcs7.detached", annotation: signature_annotation, location: location, contact: contact, issuer: issuer ) end extract_signed_pdf(parsed_pdf) end end |