Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Padding for single label #45

Open
larzknoke opened this issue Mar 8, 2021 · 3 comments
Open

Padding for single label #45

larzknoke opened this issue Mar 8, 2021 · 3 comments

Comments

@larzknoke
Copy link

Hello,

I don't know if anyone else is looking in here, but I'll try:

I there a way to add a padding/margin for the single label?

Thanks
Lars

@larzknoke larzknoke changed the title Padding for singel Label Padding for single label Mar 8, 2021
@forsbergplustwo
Copy link

It's not possible to add margin to a single label of a multi-label type. Say the type has 24 labels per page, you can change all 24 labels to have another margin/padding, but not 1 of the 24.. at least not without changing the internals of the gem a lot.

If you want to update the margin of the type itself, you'd do something like:

Prawn::Labels.types = {
  "CustomLabel" => {
    "paper_size" => "A4",
    "columns"    => 2,
    "rows"       => 2,
    "left_margin" => 28,
    "top_margin" => 28
}}

That merges the above type into the existing types already defined in the types.yaml file.

Prawn::Labels.generate("names.pdf", names, :type => "CustomLabel") do |pdf, name|
  pdf.text name
end

@larzknoke
Copy link
Author

larzknoke commented Mar 8, 2021

sorry I used the wrong words. I mean I want to set a padding for all labels on the page (red line in the screenshot). To get some margin in the label itself. The options on the LabelTypes is for the hole page not for the single label (green line).

Now I do a workaround with a table inside the label and give the cell a padding.

Bildschirmfoto 2021-03-08 um 16 53 03

@forsbergplustwo
Copy link

Ah, you do that using the margin combined with the column and row gutter label options. You'll need to do some calculation, but this would be it:

left_margin = original outer margin (green line) + desired label left margin
right_margin = original outer margin (green line) + desired label right margin
column_gutter = desired label left margin + desired label right margin

top_margin = original outer margin (green line) + desired label top margin
bottom_margin = original outer margin (green line) + desired label bottom margin
row_gutter = desired label top margin + desired label bottom margin

To get exact values, use millimeters x 2.835 to get it to the needed point values when calculating above.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants