Class: Decidim::Initiatives::PdfSignatureExample
- Inherits:
-
Object
- Object
- Decidim::Initiatives::PdfSignatureExample
- Defined in:
- 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
14 15 16 |
# File 'app/services/decidim/initiatives/pdf_signature_example.rb', line 14 def initialize(args = {}) @pdf = args.fetch(:pdf) end |
Instance Attribute Details
#pdf ⇒ Object
Returns the value of attribute pdf.
10 11 12 |
# File 'app/services/decidim/initiatives/pdf_signature_example.rb', line 10 def pdf @pdf end |
Instance Method Details
#signed_pdf ⇒ Object
Public: PDF signed using a new certificate generated by the service
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/decidim/initiatives/pdf_signature_example.rb', line 19 def signed_pdf @signed_pdf ||= begin 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 end |