File: encryption.rb

package info (click to toggle)
ruby-prawn 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,936 kB
  • ctags: 802
  • sloc: ruby: 13,906; sh: 43; makefile: 15
file content (31 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# encoding: utf-8
#
# The <code>encrypt_document</code> method, as you might have already guessed,
# is used to encrypt the PDF document.
#
# Once encrypted whoever is using the document will need the user password to
# read the document. This password can be set with the
# <code>:user_password</code> option. If this is not set the document will be
# encrypted but a password will not be needed to read the document.
#
# There are some caveats when encrypting your PDFs. Be sure to read the source
# documentation (you can find it here:
# https://github.com/prawnpdf/prawn/blob/master/lib/prawn/security.rb ) before
# using this for anything super serious.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))


# Bare encryption. No password needed.
Prawn::ManualBuilder::Example.generate("bare_encryption.pdf") do
  text "See, no password was asked but the document is still encrypted."
  encrypt_document
end


# Simple password. All permissions granted.
Prawn::ManualBuilder::Example.generate("simple_password.pdf") do
  text "You was asked for a password."
  encrypt_document(:user_password => 'foo', :owner_password => 'bar')
end