prawn-labels 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Prawn/Labels takes the guess work out of generating labels using Prawn ~> 0.11.1
4
4
 
5
+ ## Install
6
+
7
+ ```bash
8
+ $ gem install prawn-labels
9
+ ```
10
+
5
11
  ## Usage
6
12
 
7
13
  ```ruby
@@ -0,0 +1,351 @@
1
+ %PDF-1.3
2
+ %����
3
+ 1 0 obj
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
+ >>
7
+ endobj
8
+ 2 0 obj
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
11
+ >>
12
+ endobj
13
+ 3 0 obj
14
+ << /Type /Pages
15
+ /Count 8
16
+ /Kids [5 0 R 8 0 R 10 0 R 12 0 R 14 0 R 16 0 R 18 0 R 20 0 R]
17
+ >>
18
+ endobj
19
+ 4 0 obj
20
+ << /Length 448
21
+ >>
22
+ stream
23
+ q
24
+ q
25
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
26
+ q
27
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
28
+ q
29
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
30
+
31
+ BT
32
+ 36.0 478.664 Td
33
+ /F1.0 12 Tf
34
+ [<4a6f7264616e20> 40 <576974682061206c6f6e672061646472657373>] TJ
35
+ ET
36
+
37
+
38
+ BT
39
+ 36.0 464.792 Td
40
+ /F1.0 12 Tf
41
+ [<7468617420676f6573206f> 15 <76> 25 <6572206d> 10 <756c7469706c65206c696e65732062> 20 <6c61682062> 20 <6c61682062> 20 <6c6168>] TJ
42
+ ET
43
+
44
+ Q
45
+ Q
46
+ Q
47
+ Q
48
+
49
+ endstream
50
+ endobj
51
+ 5 0 obj
52
+ << /Type /Page
53
+ /Parent 3 0 R
54
+ /MediaBox [0 0 297 595.28]
55
+ /Contents 4 0 R
56
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
57
+ /Font << /F1.0 6 0 R
58
+ >>
59
+ >>
60
+ >>
61
+ endobj
62
+ 6 0 obj
63
+ << /Type /Font
64
+ /Subtype /Type1
65
+ /BaseFont /Helvetica
66
+ /Encoding /WinAnsiEncoding
67
+ >>
68
+ endobj
69
+ 7 0 obj
70
+ << /Length 234
71
+ >>
72
+ stream
73
+ q
74
+ q
75
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
76
+ q
77
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
78
+ q
79
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
80
+
81
+ BT
82
+ 36.0 478.664 Td
83
+ /F1.0 12 Tf
84
+ [<4a6f7264616e>] TJ
85
+ ET
86
+
87
+ Q
88
+ Q
89
+ Q
90
+ Q
91
+
92
+ endstream
93
+ endobj
94
+ 8 0 obj
95
+ << /Type /Page
96
+ /Parent 3 0 R
97
+ /MediaBox [0 0 297 595.28]
98
+ /Contents 7 0 R
99
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
100
+ /Font << /F1.0 6 0 R
101
+ >>
102
+ >>
103
+ >>
104
+ endobj
105
+ 9 0 obj
106
+ << /Length 239
107
+ >>
108
+ stream
109
+ q
110
+ q
111
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
112
+ q
113
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
114
+ q
115
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
116
+
117
+ BT
118
+ 36.0 478.664 Td
119
+ /F1.0 12 Tf
120
+ [<436872> -15 <6973>] TJ
121
+ ET
122
+
123
+ Q
124
+ Q
125
+ Q
126
+ Q
127
+
128
+ endstream
129
+ endobj
130
+ 10 0 obj
131
+ << /Type /Page
132
+ /Parent 3 0 R
133
+ /MediaBox [0 0 297 595.28]
134
+ /Contents 9 0 R
135
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
136
+ /Font << /F1.0 6 0 R
137
+ >>
138
+ >>
139
+ >>
140
+ endobj
141
+ 11 0 obj
142
+ << /Length 228
143
+ >>
144
+ stream
145
+ q
146
+ q
147
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
148
+ q
149
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
150
+ q
151
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
152
+
153
+ BT
154
+ 36.0 478.664 Td
155
+ /F1.0 12 Tf
156
+ [<4a6f6e>] TJ
157
+ ET
158
+
159
+ Q
160
+ Q
161
+ Q
162
+ Q
163
+
164
+ endstream
165
+ endobj
166
+ 12 0 obj
167
+ << /Type /Page
168
+ /Parent 3 0 R
169
+ /MediaBox [0 0 297 595.28]
170
+ /Contents 11 0 R
171
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
172
+ /Font << /F1.0 6 0 R
173
+ >>
174
+ >>
175
+ >>
176
+ endobj
177
+ 13 0 obj
178
+ << /Length 236
179
+ >>
180
+ stream
181
+ q
182
+ q
183
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
184
+ q
185
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
186
+ q
187
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
188
+
189
+ BT
190
+ 36.0 478.664 Td
191
+ /F1.0 12 Tf
192
+ [<4d696b> 20 <65>] TJ
193
+ ET
194
+
195
+ Q
196
+ Q
197
+ Q
198
+ Q
199
+
200
+ endstream
201
+ endobj
202
+ 14 0 obj
203
+ << /Type /Page
204
+ /Parent 3 0 R
205
+ /MediaBox [0 0 297 595.28]
206
+ /Contents 13 0 R
207
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
208
+ /Font << /F1.0 6 0 R
209
+ >>
210
+ >>
211
+ >>
212
+ endobj
213
+ 15 0 obj
214
+ << /Length 238
215
+ >>
216
+ stream
217
+ q
218
+ q
219
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
220
+ q
221
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
222
+ q
223
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
224
+
225
+ BT
226
+ 36.0 478.664 Td
227
+ /F1.0 12 Tf
228
+ [<4b> 40 <656c6c79>] TJ
229
+ ET
230
+
231
+ Q
232
+ Q
233
+ Q
234
+ Q
235
+
236
+ endstream
237
+ endobj
238
+ 16 0 obj
239
+ << /Type /Page
240
+ /Parent 3 0 R
241
+ /MediaBox [0 0 297 595.28]
242
+ /Contents 15 0 R
243
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
244
+ /Font << /F1.0 6 0 R
245
+ >>
246
+ >>
247
+ >>
248
+ endobj
249
+ 17 0 obj
250
+ << /Length 228
251
+ >>
252
+ stream
253
+ q
254
+ q
255
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
256
+ q
257
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
258
+ q
259
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
260
+
261
+ BT
262
+ 36.0 478.664 Td
263
+ /F1.0 12 Tf
264
+ [<426f62>] TJ
265
+ ET
266
+
267
+ Q
268
+ Q
269
+ Q
270
+ Q
271
+
272
+ endstream
273
+ endobj
274
+ 18 0 obj
275
+ << /Type /Page
276
+ /Parent 3 0 R
277
+ /MediaBox [0 0 297 595.28]
278
+ /Contents 17 0 R
279
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
280
+ /Font << /F1.0 6 0 R
281
+ >>
282
+ >>
283
+ >>
284
+ endobj
285
+ 19 0 obj
286
+ << /Length 230
287
+ >>
288
+ stream
289
+ q
290
+ q
291
+ 1.00000 0.00000 0.00000 1.00000 -451.28000 523.28000 cm
292
+ q
293
+ -0.00000 -1.00000 1.00000 -0.00000 0.00000 0.00000 cm
294
+ q
295
+ 1.00000 0.00000 0.00000 1.00000 0.00000 81.00000 cm
296
+
297
+ BT
298
+ 36.0 478.664 Td
299
+ /F1.0 12 Tf
300
+ [<47726567>] TJ
301
+ ET
302
+
303
+ Q
304
+ Q
305
+ Q
306
+ Q
307
+
308
+ endstream
309
+ endobj
310
+ 20 0 obj
311
+ << /Type /Page
312
+ /Parent 3 0 R
313
+ /MediaBox [0 0 297 595.28]
314
+ /Contents 19 0 R
315
+ /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
316
+ /Font << /F1.0 6 0 R
317
+ >>
318
+ >>
319
+ >>
320
+ endobj
321
+ xref
322
+ 0 21
323
+ 0000000000 65535 f
324
+ 0000000015 00000 n
325
+ 0000000109 00000 n
326
+ 0000000158 00000 n
327
+ 0000000263 00000 n
328
+ 0000000762 00000 n
329
+ 0000000939 00000 n
330
+ 0000001036 00000 n
331
+ 0000001321 00000 n
332
+ 0000001498 00000 n
333
+ 0000001788 00000 n
334
+ 0000001966 00000 n
335
+ 0000002246 00000 n
336
+ 0000002425 00000 n
337
+ 0000002713 00000 n
338
+ 0000002892 00000 n
339
+ 0000003182 00000 n
340
+ 0000003361 00000 n
341
+ 0000003641 00000 n
342
+ 0000003820 00000 n
343
+ 0000004102 00000 n
344
+ trailer
345
+ << /Size 21
346
+ /Root 2 0 R
347
+ /Info 1 0 R
348
+ >>
349
+ startxref
350
+ 4281
351
+ %%EOF
@@ -0,0 +1,8 @@
1
+ require File.join(File.dirname(__FILE__), "example_helper")
2
+
3
+ fancy_names = ["Jordan With a long address\n that goes over multiple lines blah blah blah",
4
+ "Jordan", "Chris", "Jon", "Mike", "Kelly", "Bob", "Greg"]
5
+
6
+ Prawn::Labels.generate("envelope_labels.pdf", fancy_names, :type => "Envelope10") do |pdf, name|
7
+ pdf.text name
8
+ end
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
2
  require 'rubygems'
3
3
  require 'prawn/core'
4
4
  require 'prawn/labels'
@@ -1,29 +1,25 @@
1
1
  %PDF-1.3
2
2
  %����
3
3
  1 0 obj
4
- << /Creator (Prawn)
5
- /Producer (Prawn)
4
+ << /Creator <feff0050007200610077006e>
5
+ /Producer <feff0050007200610077006e>
6
6
  >>
7
7
  endobj
8
8
  2 0 obj
9
- << /Type /Pages
10
- /Count 2
11
- /Kids [5 0 R 8 0 R]
9
+ << /Type /Catalog
10
+ /Pages 3 0 R
12
11
  >>
13
12
  endobj
14
13
  3 0 obj
15
- << /Type /Catalog
16
- /Pages 2 0 R
14
+ << /Type /Pages
15
+ /Count 2
16
+ /Kids [5 0 R 8 0 R]
17
17
  >>
18
18
  endobj
19
19
  4 0 obj
20
- << /Length 1917
20
+ << /Length 1845
21
21
  >>
22
22
  stream
23
- /DeviceRGB cs
24
- 0.000 0.000 0.000 scn
25
- /DeviceRGB CS
26
- 0.000 0.000 0.000 SCN
27
23
  q
28
24
 
29
25
  BT
@@ -241,7 +237,7 @@ endstream
241
237
  endobj
242
238
  5 0 obj
243
239
  << /Type /Page
244
- /Parent 2 0 R
240
+ /Parent 3 0 R
245
241
  /MediaBox [0 0 595.28 841.89]
246
242
  /Contents 4 0 R
247
243
  /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
@@ -258,13 +254,9 @@ endobj
258
254
  >>
259
255
  endobj
260
256
  7 0 obj
261
- << /Length 359
257
+ << /Length 287
262
258
  >>
263
259
  stream
264
- /DeviceRGB cs
265
- 0.000 0.000 0.000 scn
266
- /DeviceRGB CS
267
- 0.000 0.000 0.000 SCN
268
260
  q
269
261
 
270
262
  BT
@@ -307,7 +299,7 @@ endstream
307
299
  endobj
308
300
  8 0 obj
309
301
  << /Type /Page
310
- /Parent 2 0 R
302
+ /Parent 3 0 R
311
303
  /MediaBox [0 0 595.28 841.89]
312
304
  /Contents 7 0 R
313
305
  /Resources << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
@@ -320,18 +312,18 @@ xref
320
312
  0 9
321
313
  0000000000 65535 f
322
314
  0000000015 00000 n
323
- 0000000071 00000 n
324
- 0000000134 00000 n
325
- 0000000183 00000 n
326
- 0000002152 00000 n
327
- 0000002332 00000 n
328
- 0000002429 00000 n
329
- 0000002839 00000 n
315
+ 0000000109 00000 n
316
+ 0000000158 00000 n
317
+ 0000000221 00000 n
318
+ 0000002118 00000 n
319
+ 0000002298 00000 n
320
+ 0000002395 00000 n
321
+ 0000002733 00000 n
330
322
  trailer
331
323
  << /Size 9
332
- /Root 3 0 R
324
+ /Root 2 0 R
333
325
  /Info 1 0 R
334
326
  >>
335
327
  startxref
336
- 3019
328
+ 2913
337
329
  %%EOF
data/lib/prawn/labels.rb CHANGED
@@ -29,9 +29,11 @@ module Prawn
29
29
  raise "Label Type Unknown '#{options[:type]}'"
30
30
  end
31
31
 
32
- type["paper_size"] ||= "A4"
33
- type["top_margin"] ||= 36
34
- type["top_margin"] ||= 36
32
+ type["paper_size"] ||= "A4"
33
+ type["top_margin"] ||= 36
34
+ type["left_margin"] ||= 36
35
+
36
+ options.merge!(:vertical_text => true) if type["vertical_text"]
35
37
 
36
38
  @document = Document.new :page_size => type["paper_size"],
37
39
  :top_margin => type["top_margin"],
@@ -41,8 +43,8 @@ module Prawn
41
43
 
42
44
  generate_grid @type
43
45
 
44
- data.each_with_index do |record, i|
45
- create_label(i, record, options) do |pdf, record|
46
+ data.each_with_index do |record, index|
47
+ create_label(index, record, options) do |pdf, record|
46
48
  yield pdf, record
47
49
  end
48
50
  end
@@ -55,29 +57,41 @@ module Prawn
55
57
  @document.define_grid({ :columns => type["columns"],
56
58
  :rows => type["rows"],
57
59
  :column_gutter => type["column_gutter"],
58
- :row_gutter => type["row_gutter"],
60
+ :row_gutter => type["row_gutter"]
59
61
  })
60
62
  end
61
63
 
62
- def row_col_from_index(i)
63
- page, newi = i.divmod(@document.grid.rows * @document.grid.columns)
64
- if newi == 0 and page > 0
64
+ def row_col_from_index(index)
65
+ page, new_index = index.divmod(@document.grid.rows * @document.grid.columns)
66
+ if new_index == 0 and page > 0
65
67
  @document.start_new_page
66
68
  generate_grid @type
67
69
  return [0,0]
68
70
  end
69
- return newi.divmod(@document.grid.columns)
71
+ return new_index.divmod(@document.grid.columns)
70
72
  end
71
73
 
72
- def create_label(i, record, options = {}, &block)
73
- p = row_col_from_index(i)
74
+ def create_label(index, record, options = {}, &block)
75
+ p = row_col_from_index(index)
74
76
 
75
77
  shrink_text(record) if options[:shrink_to_fit] == true
76
78
 
77
79
  b = @document.grid(p.first, p.last)
78
- @document.bounding_box b.top_left, :width => b.width, :height => b.height do
79
- yield @document, record
80
+
81
+ if options[:vertical_text]
82
+ @document.rotate(270, :origin => b.top_left) do
83
+ @document.translate(0, b.width) do
84
+ @document.bounding_box b.top_left, :width => b.height, :height => b.width do
85
+ yield @document, record
86
+ end
87
+ end
88
+ end
89
+ else
90
+ @document.bounding_box b.top_left, :width => b.width, :height => b.height do
91
+ yield @document, record
92
+ end
80
93
  end
94
+
81
95
  end
82
96
 
83
97
  def shrink_text(record)
data/lib/prawn/types.yaml CHANGED
@@ -4,7 +4,7 @@
4
4
  #
5
5
  # Avery 7160 family: Mailing labels, 63.5 x 38.1 mm, 21 per sheet
6
6
  Avery7160:
7
- page_size: A4
7
+ paper_size: A4
8
8
  top_margin: 43.9
9
9
  bottom_margin: 0
10
10
  left_margin: 19.843
@@ -15,7 +15,7 @@ Avery7160:
15
15
  row_gutter: 0
16
16
  # Avery 5160 family
17
17
  Avery5160:
18
- page_size: A4
18
+ paper_size: A4
19
19
  top_margin: 36
20
20
  bottom_margin: 36
21
21
  left_margin: 15.822
@@ -24,6 +24,17 @@ Avery5160:
24
24
  rows: 10
25
25
  column_gutter: 10
26
26
  row_gutter: 0
27
+ #Standard #10 envelope
28
+ Envelope10:
29
+ paper_size: [297, 595.28]
30
+ vertical_text: true
31
+ columns: 1
32
+ rows: 1
33
+ right_margin: 180
34
+ left_margin: 36
35
+ top_margin: 108
36
+ bottom_margin: 208
37
+
27
38
  TEST:
28
39
  left_margin: 123
29
40
  right_margin: 789
data/prawn-labels.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- PRAWN_LABELS_VERSION = "0.11.1"
1
+ PRAWN_LABELS_VERSION = "0.11.2"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "prawn-labels"
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.authors = ["Jordan Byron"]
18
18
  spec.email = ["jordan.byron@gmail.com"]
19
19
  spec.rubyforge_project = "prawn-labels"
20
- spec.add_dependency('prawn', '~>0.11.1')
20
+ spec.add_dependency('prawn', '~>0.12.0')
21
21
  spec.homepage = "http://github.com/jordanbyron/prawn-labels"
22
22
  spec.description = <<END_DESC
23
23
  Prawn/Labels takes the guess work out of generating labels using Prawn
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 11
8
- - 1
9
- version: 0.11.1
8
+ - 2
9
+ version: 0.11.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jordan Byron
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-08 00:00:00 -04:00
17
+ date: 2011-10-02 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -27,9 +27,9 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
- - 11
31
- - 1
32
- version: 0.11.1
30
+ - 12
31
+ - 0
32
+ version: 0.12.0
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  description: " Prawn/Labels takes the guess work out of generating labels using Prawn\n"
@@ -44,6 +44,8 @@ extra_rdoc_files:
44
44
  - LICENSE
45
45
  - COPYING
46
46
  files:
47
+ - examples/envelope_labels.pdf
48
+ - examples/envelope_labels.rb
47
49
  - examples/example_helper.rb
48
50
  - examples/hello_labels.pdf
49
51
  - examples/hello_labels.rb