poppler 4.3.7 → 4.3.8

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/sample/pdfcrop.rb +72 -9
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8465a9293ba428baa9e8c09eaf8fcd9462d15acf50021d9179be8cd3e47f3046
4
- data.tar.gz: 4031551c0d35fb70389e368ab2a90042887069cab4ab2dddbe786d4baaa461ea
3
+ metadata.gz: 5890015e51d80e4163daf532eb0d9e3a98c97fd7664698eed6bbaf238c2110f5
4
+ data.tar.gz: b5714733ab60873a7afe1282ad050551c7b8ae4dc135a26d8d08f99cf2ea1c65
5
5
  SHA512:
6
- metadata.gz: 135abc60e33d9a76fecc99fa36dc95296cf6aee9c77827dddf440c1ca706697b67548fb1d62738c2a22feb5b3d2a657d437bf8d2a02757a5592c5a7312bdf480
7
- data.tar.gz: 8affcc18c5ca560ca94a6ea6767d28c67bcbcf3bf52d8bd951bc8ce02fefbc9ff4c1ac72d4ecfa3016218f1ebe3c23e8cdb48cb06310e24634bdfc0afafc01af
6
+ metadata.gz: 1cf00e2d5ecd3a0ecbb0f6583accc4393bbc87715d3f2692bf6a4d605b1bf5c4c8eb0bf035f105fad994d661e4fc84baec28523102e5ea384eddfcbee3bd6804
7
+ data.tar.gz: c956221b82bd210829cd38c889cf702f53288768eff9696018f2fdd0c920634113b05a3ff94a54a90b741de5d902b1b8b757930623476e766e3d2b0b8e143ba2
data/sample/pdfcrop.rb CHANGED
@@ -1,10 +1,56 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "optparse"
3
4
  require "poppler"
4
5
 
6
+ x_margin_ratio = 0.1
7
+ y_margin_ratio = 0.1
8
+ crop_x_offset = nil
9
+ crop_y_offset = nil
10
+ crop_width = nil
11
+ crop_height = nil
12
+ parser = OptionParser.new
13
+ parser.banner += "input.pdf output.pdf"
14
+ parser.on("--x-margin-ratio=RATIO",
15
+ Float,
16
+ "Margin ratio for X",
17
+ "(#{x_margin_ratio})") do |ratio|
18
+ x_margin_ratio = ratio
19
+ end
20
+ parser.on("--y-margin-ratio=RATIO",
21
+ Float,
22
+ "Margin ratio for Y",
23
+ "(#{y_margin_ratio})") do |ratio|
24
+ y_margin_ratio = ratio
25
+ end
26
+ parser.on("--crop-x-offset=OFFSET",
27
+ Float,
28
+ "X offset for crop",
29
+ "(0)") do |offset|
30
+ crop_x_offset = offset
31
+ end
32
+ parser.on("--crop-y-offset=OFFSET",
33
+ Float,
34
+ "Y offset for crop",
35
+ "(0)") do |offset|
36
+ crop_y_offset = offset
37
+ end
38
+ parser.on("--crop-width=WIDTH",
39
+ Float,
40
+ "Width for crop",
41
+ "(Original width)") do |width|
42
+ crop_width = width
43
+ end
44
+ parser.on("--crop-height=HEIGHT",
45
+ Integer,
46
+ "Height for crop",
47
+ "(Original height)") do |height|
48
+ crop_height = height
49
+ end
50
+ parser.parse!
5
51
  if ARGV.size != 2
6
- puts "usage: #{$0} input.pdf output.pdf"
7
- exit(-1)
52
+ puts(parser.to_s)
53
+ exit(false)
8
54
  end
9
55
 
10
56
  input, output = ARGV
@@ -12,18 +58,35 @@ input, output = ARGV
12
58
  doc = Poppler::Document.new(input)
13
59
 
14
60
  width, height = doc[0].size
15
- x_margin = width * 0.1
16
- y_margin = height * 0.1
17
- croped_width = width - (2 * x_margin)
18
- croped_height = height - (2 * y_margin)
19
- Cairo::PDFSurface.new(output, croped_width, croped_height) do |surface|
61
+ if crop_x_offset or crop_y_offset or crop_width or crop_height
62
+ x_offset = (crop_x_offset || 0)
63
+ y_offset = (crop_y_offset || 0)
64
+ cropped_width = crop_width || width
65
+ cropped_height = crop_height || height
66
+ x_margin = cropped_width * x_margin_ratio
67
+ y_margin = cropped_height * y_margin_ratio
68
+ cropped_width += x_margin * 2
69
+ cropped_height += y_margin * 2
70
+ else
71
+ x_offset = 0
72
+ y_offset = 0
73
+ x_margin = width * x_margin_ratio
74
+ y_margin = height * y_margin_ratio
75
+ cropped_width = width - (2 * x_margin)
76
+ cropped_height = height - (2 * y_margin)
77
+ end
78
+ Cairo::PDFSurface.new(output, cropped_width, cropped_height) do |surface|
20
79
  context = Cairo::Context.new(surface)
21
80
 
22
81
  doc.each do |page|
23
82
  width, height = page.size
24
83
  context.save do
25
- context.translate(-x_margin, -y_margin)
26
- context.rectangle(x_margin, y_margin, croped_width, croped_height)
84
+ context.translate(-(x_margin + x_offset),
85
+ -(y_margin + y_offset))
86
+ context.rectangle(x_margin + x_offset,
87
+ y_margin + y_offset,
88
+ cropped_width,
89
+ cropped_height)
27
90
  context.clip
28
91
  page.render(context)
29
92
  context.show_page
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poppler
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.7
4
+ version: 4.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Ruby-GNOME Project Team
@@ -15,28 +15,28 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 4.3.7
18
+ version: 4.3.8
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 4.3.7
25
+ version: 4.3.8
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: gio2
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 4.3.7
32
+ version: 4.3.8
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 4.3.7
39
+ version: 4.3.8
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rake
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,7 @@ requirements:
128
128
  - 'system: poppler-glib>0.12.0: macports: poppler'
129
129
  - 'system: poppler-glib>0.12.0: msys2: poppler'
130
130
  - 'system: poppler-glib>0.12.0: rhel: pkgconfig(poppler-glib)'
131
- rubygems_version: 4.0.10
131
+ rubygems_version: 4.0.16
132
132
  specification_version: 4
133
133
  summary: Ruby/Poppler is a Ruby binding of poppler-glib.
134
134
  test_files: []