-
Notifications
You must be signed in to change notification settings - Fork 684
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
Easier way to figure out text positioning. #957
Comments
Oh and I apologize in advance if this should be a stack question, but I figured the folks here would have a quick answer. Cheers! 👍 |
Hi, first of all, you are using templates which isn't part of core prawnpdf. My recommendation would be generating all of the pdf in prawn so positioning will be easy. |
Thanks so much for your answer. What's the best way to print a grid so I have a guideline? I've read the docs but there's a lot to cover. :) |
Here's the grid code I use to help measure and position elements. require "prawn"
module Prawn
module Graphics
def stroke_grid(options = {})
options = {
:at => [0, 0],
:height => bounds.height.to_i - (options[:at] || [0, 0])[1],
:width => bounds.width.to_i - (options[:at] || [0, 0])[0],
:step_length => 50,
:negative_axes_length => 0,
:color => "000000"
}.merge(options)
Prawn.verify_options([:at, :width, :height, :step_length,
:negative_axes_length, :color], options)
save_graphics_state do
fill_color(options[:color])
stroke_color(options[:color])
stroke_bounds
fill_circle(options[:at], 1)
(options[:step_length]..options[:width]).step(options[:step_length]) do |point|
fill_circle([options[:at][0] + point, options[:at][1]], 1)
draw_text(point, :at => [options[:at][0] + point - 5, options[:at][1] + 10], :size => 7)
end
(options[:step_length]..options[:height]).step(options[:step_length]) do |point|
fill_circle([options[:at][0], options[:at][1] + point], 1)
draw_text(point, :at => [options[:at][0] + 10, options[:at][1] + point - 2], :size => 7)
end
self.line_width = 0.5
(0..options[:height]).step(5) do |point|
tp = point % 50 == 0 ? 0.5 : 0.1
transparent(tp) do
stroke_horizontal_line(options[:at][0],
options[:at][0] + options[:width], :at => options[:at][1] + point)
end
end
(0..options[:width]).step(5) do |point|
tp = point % 50 == 0 ? 0.5 : 0.1
transparent(tp) do
stroke_vertical_line(options[:at][1],
options[:at][1] + options[:height], :at => options[:at][0] + point)
end
end
end
end
end
end
Prawn::Document.generate("grid.pdf") do
# Remove canvas to draw grid within current bounds
canvas do
stroke_grid
end
end |
I have a class with a method called `generate_pdf', the code is below:
I've got a 3 page form based off a PDF template which generates just fine. But I'm having a really hard time with the
draw_text
method specifically figuring out the positioning using:at => [0,0]
Is there some sort of tool or online resource that will make figuring out the X/Y axis for each draw_text element easier? I need all of my text fields aligned properly on the pdf in certain positions but am having a hard time making heads or tails of the grid system. I wish there was a UI for this. :) Each time I make a text change I have to reload the class in the console and regenerate the PDF to see if I'm close. This is taking countless hours. Is there a better way than doing this manually?
The text was updated successfully, but these errors were encountered: