Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pdf_forms_flag #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/princely/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -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 = ''
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/princely/pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)})

Expand Down
8 changes: 7 additions & 1 deletion spec/princely/pdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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