diff --git a/README.md b/README.md index 0364b47..5adf24d 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ The defaults for the render options are as follows: relative_paths: true server_flag: true javascript_flag: false + pdf_forms_flag: false timeout: none ## Contributors diff --git a/lib/princely/pdf.rb b/lib/princely/pdf.rb index 76b7b2a..4d8fd87 100644 --- a/lib/princely/pdf.rb +++ b/lib/princely/pdf.rb @@ -2,7 +2,7 @@ module Princely class Pdf - attr_accessor :executable, :style_sheets, :logger, :log_file, :server_flag, :media, :javascript_flag, :timeout + attr_accessor :executable, :style_sheets, :logger, :log_file, :server_flag, :media, :javascript_flag, :timeout, :pdf_forms_flag # Initialize method # @@ -14,7 +14,8 @@ def initialize(options={}) :logger => nil, :server_flag => true, :media => nil, - :javascript_flag => false + :javascript_flag => false, + :pdf_forms_flag => false, }.merge(options) @executable = options[:path] ? Princely::Executable.new(options[:path]) : options[:executable] @style_sheets = '' @@ -23,6 +24,7 @@ def initialize(options={}) @server_flag = options[:server_flag] @media = options[:media] @javascript_flag = options[:javascript_flag] + @pdf_forms_flag = options[:pdf_forms_flag] @timeout = options[:timeout] end @@ -57,6 +59,7 @@ def executable_options options << "--log=#{log_file}" options << "--media=#{media}" if media options << "--javascript" if @javascript_flag + options << "--pdf-forms" if @pdf_forms_flag options << @style_sheets options end diff --git a/lib/princely/pdf_helper.rb b/lib/princely/pdf_helper.rb index ef943c2..05109da 100644 --- a/lib/princely/pdf_helper.rb +++ b/lib/princely/pdf_helper.rb @@ -32,10 +32,11 @@ def make_pdf(options = {}) :relative_paths => true, :server_flag => true, :media => nil, - :javascript_flag => false + :javascript_flag => false, + :pdf_forms_flag => false }.merge(options) - prince = Princely::Pdf.new(options.slice(:server_flag, :javascript_flag, :media)) + prince = Princely::Pdf.new(options.slice(:server_flag, :javascript_flag, :pdf_forms_flag, :media)) # Sets style sheets on PDF renderer prince.add_style_sheets(*options[:stylesheets].collect{|style| asset_file_path(style)}) diff --git a/spec/princely/pdf_spec.rb b/spec/princely/pdf_spec.rb index ef761c8..39f4c38 100644 --- a/spec/princely/pdf_spec.rb +++ b/spec/princely/pdf_spec.rb @@ -9,7 +9,7 @@ it "generates a PDF from HTML" do pdf = Princely::Pdf.new.pdf_from_string html_doc - expect(pdf).to start_with("%PDF-1.4") + expect(pdf).to match(/\A%PDF-\d\.\d/) expect(pdf.rstrip).to end_with("%%EOF") pdf.length > 100 end @@ -78,5 +78,11 @@ allow(prince).to receive(:log_file).and_return('/tmp/test_log') expect(prince.exe_path).to eql("/tmp/fake --input=html --server --log=/tmp/test_log --javascript ") end + + it "adds the pdf-forms flag" do + prince = Princely::Pdf.new(:path => '/tmp/fake', :pdf_forms_flag => true) + allow(prince).to receive(:log_file).and_return('/tmp/test_log') + expect(prince.exe_path).to eql("/tmp/fake --input=html --server --log=/tmp/test_log --pdf-forms ") + end end end