Skip to content
Browse files

Added x_offset and y_offset capabilities at a Class and per fill_form…

…_with call
  • Loading branch information...
1 parent 7a1d209 commit d50c1f21ecd507e982d8dde1f89ccd042ab5687f @netinlet netinlet committed Mar 4, 2012
Showing with 75 additions and 3 deletions.
  1. +2 −0 Gemfile
  2. +47 −0 README.md
  3. +24 −3 lib/prawn-fillform.rb
  4. +2 −0 prawn-fillform.gemspec
View
2 Gemfile
@@ -1,4 +1,6 @@
source "http://rubygems.org"
# Specify your gem's dependencies in prawn-fillform.gemspec
+#
+gem 'prawn', :require => 'prawn'
gemspec
View
47 README.md
@@ -28,3 +28,50 @@ end
Take a look in `examples` folder
+## Per Fork netinlet/prawn-fillform
+
+I was having issue with the form field placement (see https://github.com/moessimple/prawn-fillform/issues/1)
+Scribus and Adobe Acrobat don't open pdf's in the same way so the formatting comes out differently. Much like
+opening a Word document in OpenOffice can some render with funny formatting.
+
+This fork added the ability to set :x_offset and :y_offset at the class level and on a per form basis.
+
+#Class Methods
+```ruby
+Prawn::Document.set_fillform_xy_offset(x_offset, y_offset)
+
+Prawn::Document.use_adobe_xy_offsets! # Your mileage may vary! Defaults to x_offset:2, y_offset:-40
+
+Prawn::Document.fillform_x_offset
+
+Prawn::Document.fillform_y_offset
+```
+
+#And on a per-form basis
+
+See the :options param below
+
+```ruby
+require 'prawn-fillform'
+
+data = {}
+data[:page_1] = {}
+data[:page_1][:firstname] = { :value => "Max", :options => {:x_offset => 2, :y_offset => -40} }
+data[:page_1][:lastname] = { :value => "Mustermann" }
+data[:page_1][:photo] = { :value => "test.jpg" }
+
+# Create a PDF file with predefined data Fields
+Prawn::Document.generate "output.pdf", :template => "template.pdf" do |pdf|
+ pdf.fill_form_with(data)
+end
+```
+
+
+
+
+
+
+
+
+
+
View
27 lib/prawn-fillform.rb
@@ -6,7 +6,7 @@
module Prawn
module Fillform
-
+
class Field
include Prawn::Document::Internals
@@ -152,6 +152,25 @@ def collect!
end
end
end
+
+ module XYOffsets
+ def fillform_x_offset
+ @fillform_x_offset ||= 2
+ end
+
+ def fillform_y_offset
+ @fillform_y_offset ||= -1
+ end
+
+ def set_fillform_xy_offset(x_offset, y_offset)
+ @fillform_x_offset = x_offset
+ @fillform_y_offset = y_offset
+ end
+
+ def use_adobe_xy_offsets!
+ set_fillform_xy_offset(2, -40)
+ end
+ end
def acroform_field_names
result = []
@@ -190,7 +209,6 @@ def acroform_fields
end
def fill_form_with(data={})
-
acroform_fields.each do |page, fields|
fields.each do |field|
number = page.to_s.split("_").last.to_i
@@ -203,8 +221,10 @@ def fill_form_with(data={})
value = value.to_s
if field.type == :text
fill_color options[:font_color] || field.font_color
+ x_offset = options[:x_offset] || self.class.fillform_x_offset
+ y_offset = options[:y_offset] || self.class.fillform_y_offset
- text_box value, :at => [field.x + 2, field.y - 1],
+ text_box value, :at => [field.x + x_offset, field.y + y_offset],
:align => options[:align] || field.align,
:width => options[:width] || field.width,
:height => options[:height] || field.height,
@@ -238,5 +258,6 @@ def fill_form_with(data={})
end
require 'prawn/document'
+Prawn::Document.extend Prawn::Fillform::XYOffsets
Prawn::Document.send(:include, Prawn::Fillform)
View
2 prawn-fillform.gemspec
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+
+ s.add_dependency "prawn"
# specify any dependencies here; for example:
# s.add_development_dependency "rspec"

0 comments on commit d50c1f2

Please sign in to comment.
Something went wrong with that request. Please try again.