mupdf 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7668e9689741bc823e304c97df7c135f9ed31453fedbed2d5f06e19a8be3f43
4
- data.tar.gz: ee5b8c0c417dee4b2e80a063b06fb2699753e1857e9c6c11e0d50d7448815e81
3
+ metadata.gz: 75c0956dd50c089d4cea76952bdc5c4244a946c674d4e648edc71d749bd1faca
4
+ data.tar.gz: c5fe14cf7c06739d4e03480c894ab938c4e0fa68b897bdcf4b49e0f078f33bf5
5
5
  SHA512:
6
- metadata.gz: 2b85d9364a453fabcce166ef780a6340a885d88022765488de11a09c080ff6e4770d9c92609b1a531bea062b6ceb08d1ea46035a4d8db119065d6302f49b5326
7
- data.tar.gz: a315ed8e2f213ed39a5cfe45cd742d80d73d65c8fa37bdbf3e16d96a433a34a9490ac3ec454e2efcf9e86a6dfac0abc30c9dae2406f9a18e82fa8e92cbfc94df
6
+ metadata.gz: 842db6317559209c6f2a6b0205adc8e2792c395be8fc61c0b5b23a6d750d86daf8a9642b656661efea26981cbbe6e8b64c83cd9448b470941bedc7c8011df04c
7
+ data.tar.gz: e3e79b6054b2f4f32947d62b64ca421d71efe1c949d544e99e0464503a22dde8472d4cb5da7e8cf9770d464dd7bd0f8e5b2a95d8351ab7c9347edd88405b32b9
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ gem 'rubocop'
11
11
  gem 'rubocop-rake'
12
12
  gem 'rubocop-rspec'
13
13
  gem 'simplecov'
14
+ gem 'tempfile'
14
15
  gem 'yard'
data/README.md CHANGED
@@ -12,6 +12,24 @@
12
12
  gem install mupdf
13
13
  ```
14
14
 
15
+ _This project requires `mutool` be installed on your system. To verify ensure the following works:_
16
+
17
+ ```bash
18
+ mutool
19
+ ```
20
+
21
+ To install `mutool` on MacOS use:
22
+
23
+ ```bash
24
+ brew install mupdf
25
+ ```
26
+
27
+ To install `mutool` on Ubuntu use:
28
+
29
+ ```bash
30
+ apt-get install mupdf
31
+ ```
32
+
15
33
  ## Usage
16
34
 
17
35
  ### Document
@@ -38,9 +56,19 @@ The `pages` command finds sizing information about the pages within a document:
38
56
  ```ruby
39
57
  pages = document.pages
40
58
  pages.count # e.g. 2
41
- page = pages[0]
42
- page.pagenum # 1
43
- box = page.media_box # page.crop_box / page.bleed_box / page.trim_box / page.art_box
44
- box.width # 612
45
- box.height # 792
59
+ pages.each do |page|
60
+ page.number # e.g. 1, 2, ...
61
+ page.width # 612
62
+ page.height # 792
63
+ end
64
+ ```
65
+
66
+ #### Draw
67
+
68
+ The `draw` command is useful for converting a document between formats:
69
+
70
+ ```ruby
71
+ document.pages.each do |page|
72
+ document.draw(page: page.number, format: "png", path: "./file-#{page.number}.png")
73
+ end
46
74
  ```
@@ -13,6 +13,9 @@ module MuPDF
13
13
  "#<#{self.class.name} pathname=#{@pathname}>"
14
14
  end
15
15
 
16
+ # @usage
17
+ # document.info #=> #<MuPDF::Info ...>
18
+ #
16
19
  # @raise [MuPDF::CommandError]
17
20
  #
18
21
  # @return [MuPDF::Info]
@@ -23,6 +26,14 @@ module MuPDF
23
26
  end
24
27
  end
25
28
 
29
+ # @usage
30
+ # pages = document.pages #=> [#<MuPDF::Page ...>, ...]
31
+ # pages.each do |page|
32
+ # puts page.number # e.g. 1, 2, 3, ...
33
+ # puts page.width # e.g. 612
34
+ # puts page.height # e.g. 792
35
+ # end
36
+ #
26
37
  # @raise [MuPDF::CommandError]
27
38
  #
28
39
  # @return [Array<MuPDF::Page>]
@@ -32,5 +43,28 @@ module MuPDF
32
43
  MuPDF::Page.parse(result)
33
44
  end
34
45
  end
46
+
47
+ # @usage
48
+ # Tempfile.open(['mupdf', '.png']) do |tempfile|
49
+ # document.draw(path: tempfile.path, page: 2, format: 'png')
50
+ # end
51
+ #
52
+ # @param path [String] the path where the conversion is saved
53
+ # @param format [String] "png", "svg", "txt", etc
54
+ # @param page [Integer] the page
55
+ # @param resultion [Integer] optional (default: 72)
56
+ # @param width [Integer] optional
57
+ # @param height [Integer] optional
58
+ #
59
+ # @raise [MuPDF::CommandError]
60
+ def draw(path:, page:, format: 'png', width: nil, height: nil, resolution: nil)
61
+ args = ['draw', '-o', path, '-F', format, String(@pathname), String(page)]
62
+
63
+ args << '-w' << width if width
64
+ args << '-h' << height if height
65
+ args << '-r' << resolution if resolution
66
+
67
+ MuPDF.mutool(*args)
68
+ end
35
69
  end
36
70
  end
data/lib/mupdf/page.rb CHANGED
@@ -14,14 +14,14 @@ module MuPDF
14
14
  #
15
15
  # @return [Array<MuPDF::Page>]
16
16
  def self.parse(text)
17
- text.scan(REGEX).map do |pagenum, content|
17
+ text.scan(REGEX).map do |number, content|
18
18
  new(
19
19
  media_box: parse_media_box(content),
20
20
  crop_box: parse_crop_box(content),
21
21
  art_box: parse_art_box(content),
22
22
  bleed_box: parse_bleed_box(content),
23
23
  trim_box: parse_trim_box(content),
24
- pagenum: Integer(pagenum)
24
+ number: Integer(number)
25
25
  )
26
26
  end
27
27
  end
@@ -95,19 +95,29 @@ module MuPDF
95
95
  # @param art_box [MuPDF::Box]
96
96
  # @param bleed_box [MuPDF::Box]
97
97
  # @param trim_box [MuPDF::Box]
98
- # @param pagenum [Integer]
99
- def initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, pagenum:)
98
+ # @param number [Integer]
99
+ def initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:)
100
100
  @media_box = media_box
101
101
  @crop_box = crop_box
102
102
  @art_box = art_box
103
103
  @bleed_box = bleed_box
104
104
  @trim_box = trim_box
105
- @pagenum = pagenum
105
+ @number = number
106
106
  end
107
107
 
108
108
  # @return [String]
109
109
  def inspect
110
- "#<#{self.class.name} pagenum=#{pagenum}>"
110
+ "#<#{self.class.name} number=#{@number}>"
111
+ end
112
+
113
+ # @return [Integer]
114
+ def width
115
+ @media_box.width
116
+ end
117
+
118
+ # @return [Integer]
119
+ def height
120
+ @media_box.height
111
121
  end
112
122
  end
113
123
  end
data/lib/mupdf/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuPDF
4
- VERSION = '0.4.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mupdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-03 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open3
@@ -62,8 +62,8 @@ licenses:
62
62
  metadata:
63
63
  rubygems_mfa_required: 'true'
64
64
  homepage_uri: https://github.com/ksylvest/mupdf
65
- source_code_uri: https://github.com/ksylvest/mupdf/tree/v0.4.0
66
- changelog_uri: https://github.com/ksylvest/mupdf/releases/tag/v0.4.0
65
+ source_code_uri: https://github.com/ksylvest/mupdf/tree/v1.0.0
66
+ changelog_uri: https://github.com/ksylvest/mupdf/releases/tag/v1.0.0
67
67
  documentation_uri: https://mupdf.ksylvest.com/
68
68
  post_install_message:
69
69
  rdoc_options: []