combine_pdf 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60f4dfc06ecb66c5c876b69028868bbd5bb7cde9
4
- data.tar.gz: 5a0944cbfdbc39283fbb62a2205f5897ecbb6dd0
3
+ metadata.gz: 5d032a7ab4e8768046189f88860518e5de8f977f
4
+ data.tar.gz: 65c57d46be5f5cb0ec5a0fcbfbcfef207c3336cf
5
5
  SHA512:
6
- metadata.gz: fea4291167b6d5f0585bba371467e552dafbc32aeb957312a28fda7e0431bac20f35c49ee64bf36fac0b7c18ce5d1c89097db18e3af8170318c6401a56c07af7
7
- data.tar.gz: 329afc35c2754b77b77fec6606be4e6938f535bff5e7bc1e0f1b02bf75dbf077174221448ec86cbcf0109a42e77446a9041079a75fc727bc16503b93d5151b8d
6
+ metadata.gz: 0d9482bb42b38330f701644bdf41461ddf625a55625c7e1073b1e76fd09d9bada40c643c573b6a9c60fd4a6c6b6365642863b0e524100916755918973133820f
7
+ data.tar.gz: 79f5bc78ccbf0cafcb11a5c38a9bf16ac23d1123d0cfc307397dd42baeb23facc82f015556614f7195cfaf43072d2961fc148e03901661099bb446a8c0a8fb39
data/CHANGELOG.md CHANGED
@@ -2,15 +2,23 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.2.2
6
+
7
+ **fix**: fixed the default value for the :location attribute of PDF#stamp_pages(String, options). Now, instead of the default stamp being written at [:top, :bottom], it's default location will be set to [:center].
8
+
9
+ **fix**: fixed the 'center' location in the page numbering, so that it wouldn't enforce a small font on an all page centered number.
10
+
11
+ ***
12
+
5
13
  Change log v.0.2.1
6
14
 
7
15
  **fix**: better page stamping... or, at least more secure (we hope).
8
16
 
9
- **feature**: added the PDF#stamp shortcut method. Credit to Tania (@taniarv) for the concept.
17
+ **feature**: added the PDF#stamp_pages shortcut method. Credit to Tania (@taniarv) for the concept.
10
18
 
11
19
  **fix**: possible string encoding issues could have arose when strings were rendered to PDF format. Credit to Tania (@taniarv) for exposing the issue.
12
20
 
13
- **feature**: Metadata is now easiyer to set by allowing fast access to the Information header when using PDF#save and PDF#to_pdf. Credit to Tania (@taniarv) for code.
21
+ **feature**: Metadata is now easier to set by allowing fast access to the Information header when using PDF#save and PDF#to_pdf. Credit to Tania (@taniarv) for code.
14
22
 
15
23
  ***
16
24
 
@@ -350,56 +350,72 @@ module CombinePDF
350
350
  opt = {
351
351
  number_format: ' - %s - ',
352
352
  start_at: 1,
353
- font_size: 12,
354
353
  font: :Helvetica,
355
354
  margin_from_height: 45,
356
355
  margin_from_side: 15
357
356
  }
358
357
  opt.update options
359
- opt[:number_location] ||= opt[:stamp_location] ||= opt[:location] ||= [:top, :bottom]
358
+ opt[:location] ||= opt[:number_location] ||= opt[:stamp_location] ||= [:top, :bottom]
359
+ opt[:location] = [opt[:location]] unless opt[:location].is_a? (Array)
360
+
360
361
  page_number = opt[:start_at]
361
362
  format_repeater = opt[:number_format].count('%')
363
+ just_center = [:center]
364
+ small_font_size = opt[:font_size] || 12
365
+
362
366
  (opt[:page_range] ? pages[opt[:page_range]] : pages).each do |page|
363
367
  # Get page dimensions
364
368
  mediabox = page[:CropBox] || page[:MediaBox] || [0, 0, 595.3, 841.9]
365
369
  # set stamp text
366
370
  text = opt[:number_format] % (Array.new(format_repeater) {page_number})
367
- # text = opt[:number_format] % page_number
368
- # compute locations for text boxes
369
- text_dimantions = page.dimensions_of( text, opt[:font], opt[:font_size] )
370
- box_width = text_dimantions[0] * 1.2
371
- box_height = text_dimantions[1] * 2
372
- opt[:width] = box_width
373
- opt[:height] = box_height
374
- from_height = opt[:margin_from_height]
375
- from_side = opt[:margin_from_side]
376
- page_width = mediabox[2]
377
- page_height = mediabox[3]
378
- center_position = (page_width - box_width)/2
379
- left_position = from_side
380
- right_position = page_width - from_side - box_width
381
- top_position = page_height - from_height
382
- bottom_position = from_height + box_height
383
- if opt[:number_location].include? :top
384
- page.textbox text, {x: center_position, y: top_position }.merge(opt)
385
- end
386
- if opt[:number_location].include? :bottom
387
- page.textbox text, {x: center_position, y: bottom_position }.merge(opt)
388
- end
389
- if opt[:number_location].include? :top_left
390
- page.textbox text, {x: left_position, y: top_position }.merge(opt)
391
- end
392
- if opt[:number_location].include? :bottom_left
393
- page.textbox text, {x: left_position, y: bottom_position }.merge(opt)
394
- end
395
- if opt[:number_location].include? :top_right
396
- page.textbox text, {x: right_position, y: top_position }.merge(opt)
397
- end
398
- if opt[:number_location].include? :bottom_right
399
- page.textbox text, {x: right_position, y: bottom_position }.merge(opt)
371
+ if opt[:location].include? :center
372
+ add_opt = {}
373
+ if opt[:margin_from_height] && !opt[:height] && !opt[:y]
374
+ add_opt[:height] = mediabox[3] - mediabox[1] - (2*opt[:margin_from_height].to_f)
375
+ add_opt[:y] = opt[:margin_from_height]
376
+ end
377
+ if opt[:margin_from_side] && !opt[:width] && !opt[:x]
378
+ add_opt[:width] = mediabox[2] - mediabox[0] - (2*opt[:margin_from_side].to_f)
379
+ add_opt[:x] = opt[:margin_from_side]
380
+ end
381
+ page.textbox text, opt.merge(add_opt)
400
382
  end
401
- if opt[:number_location].include? :center
402
- page.textbox text, opt
383
+ unless opt[:location] == just_center
384
+ add_opt = { font_size: small_font_size }.merge(opt)
385
+ # text = opt[:number_format] % page_number
386
+ # compute locations for text boxes
387
+ text_dimantions = page.dimensions_of( text, opt[:font], small_font_size )
388
+ box_width = text_dimantions[0] * 1.2
389
+ box_height = text_dimantions[1] * 2
390
+ add_opt[:width] ||= box_width
391
+ add_opt[:height] ||= box_height
392
+ from_height = add_opt[:margin_from_height]
393
+ from_side = add_opt[:margin_from_side]
394
+ page_width = mediabox[2]
395
+ page_height = mediabox[3]
396
+ center_position = (page_width - box_width)/2
397
+ left_position = from_side
398
+ right_position = page_width - from_side - box_width
399
+ top_position = page_height - from_height
400
+ bottom_position = from_height + box_height
401
+ if opt[:location].include? :top
402
+ page.textbox text, {x: center_position, y: top_position }.merge(add_opt)
403
+ end
404
+ if opt[:location].include? :bottom
405
+ page.textbox text, {x: center_position, y: bottom_position }.merge(add_opt)
406
+ end
407
+ if opt[:location].include? :top_left
408
+ page.textbox text, {x: left_position, y: top_position, font_size: small_font_size }.merge(add_opt)
409
+ end
410
+ if opt[:location].include? :bottom_left
411
+ page.textbox text, {x: left_position, y: bottom_position, font_size: small_font_size }.merge(add_opt)
412
+ end
413
+ if opt[:location].include? :top_right
414
+ page.textbox text, {x: right_position, y: top_position, font_size: small_font_size }.merge(add_opt)
415
+ end
416
+ if opt[:location].include? :bottom_right
417
+ page.textbox text, {x: right_position, y: bottom_position, font_size: small_font_size }.merge(add_opt)
418
+ end
403
419
  end
404
420
  page_number = page_number.succ
405
421
  end
@@ -411,12 +427,15 @@ module CombinePDF
411
427
  # stamp:: either a String or a PDF page. If this is a String, you can add formating to add page numbering (i.e. "page number %i"). otherwise remember to escape any percent ('%') sign (i.e. "page \%number not shown\%").
412
428
  # options:: an options Hash.
413
429
  #
430
+ # If the stamp is a PDF page, only :page_range and :underlay (to reverse-stamp) are valid options.
431
+ #
414
432
  # If the stamp is a String, than all the options used by {#number_pages} or {Page_Methods#textbox} can be used.
415
433
  #
416
- # If the stamp is a PDF page, only :page_range and :underlay (to reverse-stamp) are valid options.
434
+ # The default :location option is :center = meaning the stamp will be stamped all across the page unless the :x, :y, :width or :height options are specified.
417
435
  def stamp_pages stamp, options = {}
418
436
  case stamp
419
437
  when String
438
+ options[:location] ||= [:center]
420
439
  number_pages({number_format: stamp}.merge(options))
421
440
  when Page_Methods
422
441
  # stamp = stamp.copy(true)
@@ -1,3 +1,3 @@
1
1
  module CombinePDF
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combine_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-18 00:00:00.000000000 Z
11
+ date: 2015-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4