Passing custom "paper_size" in custom label type hash is ignored
dan-griffin-ct opened this issue ยท 5 comments
I'm passing prawn-labels a custom hash:
Prawn::Labels.types = {
"4x51UP" => {
"paper_size" => [360, 288],
"top_margin" => 18,
"bottom_margin" => 10,
"left_margin" => 10,
"right_margin" => 10,
"columns" => 1,
"rows" => 1,
"column_gutter" => 10,
"row_gutter" => 10
}
}
I'm finding a discrepancy in passing that custom paper size [5" W, 4" L] vs. what is generated in terms of the label size in the pdf generated, which is still the standard A4 (8.5" x 11") size. To test, I passed a known Prawn size (C7) and indeed it did change the size of the pdf generated. All other size variables immediately reflect changes imposed (e.g. margins), and I believe I'm following the guidelines as stipulated in the README.
Looking for some help with this. Any feedback/input would be greatly appreciated!
*Attached are two pdfs generated from the custom hash, the first uses [360, 288] paper size, the second Prawn size C7.
Hey @dangoldgriff,
Sorry to hear you are having trouble with the gem. From my tests it appears the page size option is working as expected. Check out this simplified example:
Prawn::Labels.types = {
"4x51UP" => {
"paper_size" => [360, 288],
"top_margin" => 18,
"bottom_margin" => 10,
"left_margin" => 10,
"right_margin" => 10,
"columns" => 1,
"rows" => 1,
"column_gutter" => 10,
"row_gutter" => 10
}
}
names = ["Jordan"]
Prawn::Labels.generate("names.pdf", names, :type => "4x51UP") do |pdf, name|
pdf.text name
end
Resulting PDF
If possible perhaps you could share your code or use the code above as a starting point to figure out what's going wrong. ๐
Hey @jordanbyron thanks for the speedy response!
I am dynamically generating type as follows:
( code, data, :type => "#{@label_var.label_var_2.template_name}") do |pdf, label_data|
I'm realize I could also try passing in that file as YAML, but interested in figuring out why this one is acting up. ๐ Should mention I work in a private repository, so code will slightly altered.
Could you verify @label_var.label_var_2.template_name
is returning what you think it is either by using pry or raising the value. For example add this line right before your call to Prawn::Labels
raise @label_var.label_var_2.template_name.inspect
Based on your initial code example I'd expect @label_var.label_var_2.template_name
to return the string "4x51UP". You also might want to check the value of your custom label type right before that line. Make sure the values match what you expect them to be.
raise Prawn::Labels.types["4x51UP"].inspect
Lastly, assuming @label_var.label_var_2.template_name
is returning a string you don't need to wrap it in quotes:
(code, data, :type => @label_var.label_var_2.template_name) do |pdf, label_data|
Hopefully that helps, but if not just let me know. I'll be here sitting by the fire watching the snow fall โ๏ธ โ
Enjoy that fire! ๐ฅ ๐
Indeed inspecting the template_name showed that it was double wrapping the template name.
"\"4x51UP\""
I removed the interpolation and voila!
Thanks for the help @jordanbyron and have a great Thanksgiving!