pludoni_pdfutils 0.2.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: 561f53e393a627ae11963fa8254bb39b8445d574dd38b05a558c3088b87ab7d5
4
- data.tar.gz: baa9dedf3eb2f0c76630c1f598ad8acc99b6eeba5c6ce5a6b6370f793f6263e9
3
+ metadata.gz: 2d8493c8060dffe855122702e48a5cb28d43292f0dc192f768d6b033c9f6a2e7
4
+ data.tar.gz: 18d0541e7a26189a90d97cc7ce5b16fd93a5e46f5e05b0885afc752919fa485e
5
5
  SHA512:
6
- metadata.gz: 06e78bd0c4608b45415f79f132be1ac7b4adbd70dba1c2df0069fa2216582c1e71ecbf156b891692e0b49b43c071f3b32a2c18209bac52d626379311e88711fa
7
- data.tar.gz: 6f69bf3240182880b623f31cb7621809df0e48d41c241db917b76b03c8e547bd8d4e3457778131d77066e758670220c90f611f541323695ca38e2694c8db5991
6
+ metadata.gz: 95d9e311f1cba3fa1dd0a96e294432f0c4c1d8777dfc5b137d8839ce09b709d0c4811b01f434ea2ad660484938cc0aef8d89a093af699012743af631da8a43b7
7
+ data.tar.gz: 5c78e1a7799432e25c2b2502fbfd1add93d3b17ebebbfc18632b721fbf2efd030161498ff5773ed6ef20a56ed531006d76b742502d0d1a561480ff2fc6ee5a6f
data/Gemfile.lock CHANGED
@@ -1,88 +1,86 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pludoni-pdfutils (0.1.0)
4
+ pludoni_pdfutils (0.4.0)
5
5
  activestorage (>= 5.2.0)
6
- mimemagic
6
+ marcel
7
7
  zeitwerk
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (6.1.7)
13
- actionview (= 6.1.7)
14
- activesupport (= 6.1.7)
15
- rack (~> 2.0, >= 2.0.9)
12
+ actionpack (7.0.7.2)
13
+ actionview (= 7.0.7.2)
14
+ activesupport (= 7.0.7.2)
15
+ rack (~> 2.0, >= 2.2.4)
16
16
  rack-test (>= 0.6.3)
17
17
  rails-dom-testing (~> 2.0)
18
18
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
- actionview (6.1.7)
20
- activesupport (= 6.1.7)
19
+ actionview (7.0.7.2)
20
+ activesupport (= 7.0.7.2)
21
21
  builder (~> 3.1)
22
22
  erubi (~> 1.4)
23
23
  rails-dom-testing (~> 2.0)
24
24
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
25
- activejob (6.1.7)
26
- activesupport (= 6.1.7)
25
+ activejob (7.0.7.2)
26
+ activesupport (= 7.0.7.2)
27
27
  globalid (>= 0.3.6)
28
- activemodel (6.1.7)
29
- activesupport (= 6.1.7)
30
- activerecord (6.1.7)
31
- activemodel (= 6.1.7)
32
- activesupport (= 6.1.7)
33
- activestorage (6.1.7)
34
- actionpack (= 6.1.7)
35
- activejob (= 6.1.7)
36
- activerecord (= 6.1.7)
37
- activesupport (= 6.1.7)
28
+ activemodel (7.0.7.2)
29
+ activesupport (= 7.0.7.2)
30
+ activerecord (7.0.7.2)
31
+ activemodel (= 7.0.7.2)
32
+ activesupport (= 7.0.7.2)
33
+ activestorage (7.0.7.2)
34
+ actionpack (= 7.0.7.2)
35
+ activejob (= 7.0.7.2)
36
+ activerecord (= 7.0.7.2)
37
+ activesupport (= 7.0.7.2)
38
38
  marcel (~> 1.0)
39
39
  mini_mime (>= 1.1.0)
40
- activesupport (6.1.7)
40
+ activesupport (7.0.7.2)
41
41
  concurrent-ruby (~> 1.0, >= 1.0.2)
42
42
  i18n (>= 1.6, < 2)
43
43
  minitest (>= 5.1)
44
44
  tzinfo (~> 2.0)
45
- zeitwerk (~> 2.3)
46
45
  builder (3.2.4)
47
- concurrent-ruby (1.1.10)
46
+ concurrent-ruby (1.2.2)
48
47
  crass (1.0.6)
49
- erubi (1.11.0)
50
- globalid (1.0.0)
48
+ erubi (1.12.0)
49
+ globalid (1.1.0)
51
50
  activesupport (>= 5.0)
52
- i18n (1.12.0)
51
+ i18n (1.14.1)
53
52
  concurrent-ruby (~> 1.0)
54
- loofah (2.19.0)
53
+ loofah (2.21.3)
55
54
  crass (~> 1.0.2)
56
- nokogiri (>= 1.5.9)
55
+ nokogiri (>= 1.12.0)
57
56
  marcel (1.0.2)
58
- mimemagic (0.4.3)
59
- nokogiri (~> 1)
60
- rake
61
- mini_mime (1.1.2)
62
- minitest (5.16.3)
63
- nokogiri (1.13.8-x86_64-linux)
57
+ mini_mime (1.1.5)
58
+ minitest (5.19.0)
59
+ nokogiri (1.15.4-x86_64-linux)
64
60
  racc (~> 1.4)
65
- racc (1.6.0)
66
- rack (2.2.4)
67
- rack-test (2.0.2)
61
+ racc (1.7.1)
62
+ rack (2.2.8)
63
+ rack-test (2.1.0)
68
64
  rack (>= 1.3)
69
- rails-dom-testing (2.0.3)
70
- activesupport (>= 4.2.0)
65
+ rails-dom-testing (2.2.0)
66
+ activesupport (>= 5.0.0)
67
+ minitest
71
68
  nokogiri (>= 1.6)
72
- rails-html-sanitizer (1.4.3)
73
- loofah (~> 2.3)
69
+ rails-html-sanitizer (1.6.0)
70
+ loofah (~> 2.21)
71
+ nokogiri (~> 1.14)
74
72
  rake (13.0.6)
75
- tzinfo (2.0.5)
73
+ tzinfo (2.0.6)
76
74
  concurrent-ruby (~> 1.0)
77
- zeitwerk (2.6.0)
75
+ zeitwerk (2.6.11)
78
76
 
79
77
  PLATFORMS
80
78
  x86_64-linux
81
79
 
82
80
  DEPENDENCIES
83
81
  bundler
84
- pludoni-pdfutils!
82
+ pludoni_pdfutils!
85
83
  rake
86
84
 
87
85
  BUNDLED WITH
88
- 2.3.15
86
+ 2.4.2
@@ -6,7 +6,7 @@ module Pludoni
6
6
  end
7
7
 
8
8
  def to_tf
9
- file = Tempfile.new(["ActiveStorage-#{@file.id}-", @file.filename.extension_with_delimiter])
9
+ file = Tempfile.new([@file.filename.base, @file.filename.extension_with_delimiter])
10
10
  ActiveStorage::Downloader.new(@file.service).send(:download, @file.key, file)
11
11
  file
12
12
  end
@@ -7,7 +7,8 @@ module Pludoni::Pdfutils
7
7
  end
8
8
 
9
9
  def run
10
- tf = Tempfile.new(['joiner', '.pdf'])
10
+ fname = File.basename(@blob.filename.to_s, '.*')
11
+ tf = Tempfile.new([fname, '.pdf'])
11
12
  tf.binmode
12
13
  input = @blob.to_tf
13
14
  cli = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=#{Shellwords.escape tf.path} #{Shellwords.escape input.path}"
@@ -17,7 +18,7 @@ module Pludoni::Pdfutils
17
18
  raise CompressionFailed, "PDF Compression failed: \nStdout: #{stdout}\nStderr: #{stderr}"
18
19
  end
19
20
 
20
- FileWrapper.make(tf)
21
+ FileWrapper.make(tf, filename: fname + ".pdf")
21
22
  end
22
23
  end
23
24
  end
@@ -7,9 +7,10 @@ module Pludoni::Pdfutils
7
7
  end
8
8
 
9
9
  def run(&block)
10
+ fname = File.basename(@blob.filename.to_s, File.extname(@blob.filename.to_s))
10
11
  @blob.open do |source|
11
12
  # convert image to pdf
12
- tf = Tempfile.new(['convert', '.pdf'])
13
+ tf = Tempfile.new([fname, '.pdf'])
13
14
  tf.binmode
14
15
 
15
16
  command = ['soffice']
@@ -32,7 +33,7 @@ module Pludoni::Pdfutils
32
33
 
33
34
  tf.open
34
35
 
35
- FileWrapper.make(tf)
36
+ FileWrapper.make(tf, filename: "#{fname}.pdf")
36
37
  end
37
38
  end
38
39
  end
@@ -7,9 +7,10 @@ module Pludoni::Pdfutils
7
7
  end
8
8
 
9
9
  def run(&block)
10
+ fname = File.basename(@blob.filename.to_s, '.*')
10
11
  @blob.open do |source|
11
12
  # convert image to pdf
12
- tf = Tempfile.new(['convert', '.pdf'])
13
+ tf = Tempfile.new([fname, '.pdf'])
13
14
  tf.binmode
14
15
  cli = "gs -dNOSAFER -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite -o #{tf.path} viewjpeg.ps -c \\(#{source.path}\\) viewJPEG"
15
16
 
@@ -18,7 +19,7 @@ module Pludoni::Pdfutils
18
19
  raise ConversionFailedError, "PDF convertion failed: Command: #{cli}\nStdout: #{stdout}\nStderr: #{stderr}"
19
20
  end
20
21
 
21
- FileWrapper.make(tf)
22
+ FileWrapper.make(tf, filename: "#{fname}.pdf")
22
23
  end
23
24
  end
24
25
  end
@@ -5,12 +5,16 @@ module Pludoni
5
5
  @file = file
6
6
  end
7
7
 
8
- def self.make(blob_or_file)
8
+ def self.make(blob_or_file, filename: nil)
9
9
  case blob_or_file
10
10
  when ActiveStorage::Blob
11
11
  ActiveStorageWrapper.new(blob_or_file)
12
12
  when File, Tempfile
13
- LocalFileWrapper.new(blob_or_file)
13
+ fw = LocalFileWrapper.new(blob_or_file)
14
+ if filename
15
+ fw.filename = filename
16
+ end
17
+ fw
14
18
  when FileWrapper
15
19
  blob_or_file
16
20
  else
@@ -32,5 +36,3 @@ module Pludoni
32
36
  end
33
37
  end
34
38
  end
35
-
36
-
@@ -7,17 +7,18 @@ module Pludoni::Pdfutils
7
7
  end
8
8
 
9
9
  def run
10
- tf = Tempfile.new(['joiner', '.pdf'])
10
+ fname = @blobs.map(&:filename).map { |i| i.split('.').first[0..20] }.join('-')
11
+
12
+ tf = Tempfile.new([fname, '.pdf'])
11
13
  tf.binmode
12
14
  tfs = @blobs.map { |i| i.to_tf }
13
15
  cli = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=#{tf.path} #{tfs.map(&:path).join(' ')}"
14
-
15
- stdout, stderr, status = Open3.capture3(cli)
16
+ stdout, stderr, status = Open3.capture3(cli)
16
17
  unless status.success?
17
18
  raise JoiningFailedError, "PDF Joining failed: \nStdout: #{stdout}\nStderr: #{stderr}"
18
19
  end
19
20
 
20
- FileWrapper.make(tf)
21
+ FileWrapper.make(tf, filename: "#{fname}.pdf")
21
22
  end
22
23
  end
23
24
  end
@@ -1,12 +1,15 @@
1
+ require 'marcel'
1
2
  module Pludoni
2
3
  module Pdfutils
3
4
  class LocalFileWrapper < FileWrapper
5
+ attr_writer :filename
6
+
4
7
  def filesize
5
8
  @file.size
6
9
  end
7
10
 
8
11
  def filename
9
- @file.path.split("/").last
12
+ @filename || @file.path.split("/").last
10
13
  end
11
14
 
12
15
  def to_tf
@@ -19,7 +22,7 @@ module Pludoni
19
22
  end
20
23
 
21
24
  def content_type
22
- MimeMagic.by_magic(@file.read).type
25
+ Marcel::MimeType.for(@file)
23
26
  ensure
24
27
  @file.rewind
25
28
  end
@@ -1,5 +1,3 @@
1
- require 'mimemagic'
2
-
3
1
  module Pludoni
4
2
  module Pdfutils
5
3
  class Error < StandardError; end
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "pludoni_pdfutils"
4
- spec.version = "0.2.0"
4
+ spec.version = "0.4.0"
5
5
  spec.authors = ["Stefan Wienert"]
6
6
  spec.email = ["info@stefanwienert.de"]
7
7
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "activestorage", ">= 5.2.0"
21
21
  spec.add_dependency "zeitwerk"
22
- spec.add_dependency "mimemagic"
22
+ spec.add_dependency "marcel"
23
23
 
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pludoni_pdfutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Wienert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-06 00:00:00.000000000 Z
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mimemagic
42
+ name: marcel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.3
128
+ rubygems_version: 3.2.33
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Convert to pdf, compress pdf, join pdf using Ghostscript