libis-format 1.0.1 → 2.0.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.
Files changed (222) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -1
  3. data/.travis.yml +43 -25
  4. data/README.md +2 -2
  5. data/base/Dockerfile +35 -0
  6. data/base/Dockerfile.alpine +20 -0
  7. data/base/Dockerfile.rvm +56 -0
  8. data/base/rework_path +20 -0
  9. data/bin/libis_format +8 -0
  10. data/docker_cfg.yml +1 -0
  11. data/lib/libis/format.rb +5 -1
  12. data/lib/libis/format/cli/convert.rb +310 -0
  13. data/lib/libis/format/cli/format.rb +77 -0
  14. data/lib/libis/format/cli/prompt_helper.rb +87 -0
  15. data/lib/libis/format/cli/sub_command.rb +22 -0
  16. data/lib/libis/format/command_line.rb +25 -0
  17. data/lib/libis/format/config.rb +14 -10
  18. data/lib/libis/format/converter/audio_converter.rb +3 -37
  19. data/lib/libis/format/converter/base.rb +21 -8
  20. data/lib/libis/format/converter/chain.rb +3 -3
  21. data/lib/libis/format/converter/image_assembler.rb +82 -0
  22. data/lib/libis/format/converter/image_converter.rb +36 -134
  23. data/lib/libis/format/converter/image_splitter.rb +80 -0
  24. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  25. data/lib/libis/format/converter/jp2_converter.rb +2 -2
  26. data/lib/libis/format/converter/office_converter.rb +2 -2
  27. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  28. data/lib/libis/format/converter/pdf_converter.rb +33 -89
  29. data/lib/libis/format/converter/pdf_optimizer.rb +70 -0
  30. data/lib/libis/format/converter/pdf_splitter.rb +65 -0
  31. data/lib/libis/format/converter/pdf_watermarker.rb +110 -0
  32. data/lib/libis/format/converter/spreadsheet_converter.rb +2 -2
  33. data/lib/libis/format/converter/video_converter.rb +1 -1
  34. data/lib/libis/format/identifier.rb +7 -7
  35. data/lib/libis/format/info.rb +27 -0
  36. data/lib/libis/format/library.rb +147 -0
  37. data/lib/libis/format/tool/droid.rb +2 -2
  38. data/lib/libis/format/tool/extension_identification.rb +4 -4
  39. data/lib/libis/format/tool/ffmpeg.rb +1 -1
  40. data/lib/libis/format/tool/fido.rb +1 -1
  41. data/lib/libis/format/tool/fop_pdf.rb +1 -1
  42. data/lib/libis/format/tool/identification_tool.rb +6 -6
  43. data/lib/libis/format/tool/office_to_pdf.rb +1 -1
  44. data/lib/libis/format/tool/pdf_copy.rb +1 -1
  45. data/lib/libis/format/tool/pdf_merge.rb +1 -1
  46. data/lib/libis/format/tool/pdf_split.rb +1 -1
  47. data/lib/libis/format/tool/pdf_to_pdfa.rb +1 -2
  48. data/lib/libis/format/tool/pdfa_validator.rb +3 -4
  49. data/lib/libis/format/tool/spreadsheet_to_ods.rb +2 -1
  50. data/lib/libis/format/version.rb +1 -1
  51. data/lib/libis/format/yaml_loader.rb +71 -0
  52. data/libis-format.gemspec +4 -4
  53. data/tools/fop/build/fop.jar +0 -0
  54. data/tools/fop/conf/fop.xconf +466 -0
  55. data/tools/fop/fop +258 -0
  56. data/tools/fop/fop.bat +75 -0
  57. data/tools/fop/fop.cmd +31 -0
  58. data/tools/fop/fop.js +341 -0
  59. data/tools/fop/lib/README.txt +243 -0
  60. data/tools/fop/lib/avalon-framework-api-4.3.1.jar +0 -0
  61. data/tools/fop/lib/avalon-framework-impl-4.3.1.jar +0 -0
  62. data/tools/fop/lib/avalon-framework.LICENSE.txt +175 -0
  63. data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -0
  64. data/tools/fop/lib/batik-all-1.10.jar +0 -0
  65. data/tools/fop/lib/batik.LICENSE.txt +201 -0
  66. data/tools/fop/lib/batik.NOTICE.txt +18 -0
  67. data/tools/fop/lib/commons-io-1.3.1.jar +0 -0
  68. data/tools/fop/lib/commons-io.LICENSE.txt +203 -0
  69. data/tools/fop/lib/commons-io.NOTICE.txt +6 -0
  70. data/tools/fop/lib/commons-logging-1.0.4.jar +0 -0
  71. data/tools/fop/lib/commons-logging.LICENSE.txt +202 -0
  72. data/tools/fop/lib/commons-logging.NOTICE.txt +3 -0
  73. data/tools/fop/lib/fontbox-2.0.7.jar +0 -0
  74. data/tools/fop/lib/serializer-2.7.2.jar +0 -0
  75. data/tools/fop/lib/serializer.LICENSE.txt +201 -0
  76. data/tools/fop/lib/serializer.NOTICE.txt +15 -0
  77. data/tools/fop/lib/xalan-2.7.2.jar +0 -0
  78. data/tools/fop/lib/xalan.BCEL.LICENSE.txt +52 -0
  79. data/tools/fop/lib/xalan.LICENSE.txt +202 -0
  80. data/tools/fop/lib/xalan.NOTICE.txt +44 -0
  81. data/tools/fop/lib/xalan.regexp.LICENSE.txt +52 -0
  82. data/tools/fop/lib/xalan.runtime.LICENSE.txt +20 -0
  83. data/tools/fop/lib/xerces.LICENSE.txt +56 -0
  84. data/tools/fop/lib/xercesImpl-2.9.1.jar +0 -0
  85. data/tools/fop/lib/xercesImpl.LICENSE.txt +201 -0
  86. data/tools/fop/lib/xercesImpl.NOTICE.txt +14 -0
  87. data/tools/fop/lib/xml-apis-1.3.04.jar +0 -0
  88. data/tools/fop/lib/xml-apis-ext-1.3.04.jar +0 -0
  89. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-documentation.txt +73 -0
  90. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-software.txt +61 -0
  91. data/tools/fop/lib/xml-apis-ext.LICENSE.sac.html +75 -0
  92. data/tools/fop/lib/xml-apis-ext.LICENSE.txt +202 -0
  93. data/tools/fop/lib/xml-apis-ext.NOTICE.txt +16 -0
  94. data/tools/fop/lib/xml-apis-ext.README.dom.txt +56 -0
  95. data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -0
  96. data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -0
  97. data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -0
  98. data/tools/fop/lib/xml-apis.LICENSE.txt +201 -0
  99. data/tools/fop/lib/xml-apis.NOTICE.txt +13 -0
  100. data/tools/fop/lib/xmlgraphics-commons-2.3.jar +0 -0
  101. data/tools/fop/lib/xmlgraphics-commons.LICENSE.txt +202 -0
  102. data/tools/fop/lib/xmlgraphics-commons.NOTICE.txt +5 -0
  103. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
  104. data/tools/pdfbox/{pdfbox-app-1.8.10.jar → preflight-app-2.0.13.jar} +0 -0
  105. metadata +78 -252
  106. data/lib/libis/format/type_database.rb +0 -201
  107. data/spec/converter_audio_spec.rb +0 -66
  108. data/spec/converter_fop_spec.rb +0 -37
  109. data/spec/converter_image_spec.rb +0 -166
  110. data/spec/converter_office_spec.rb +0 -84
  111. data/spec/converter_pdf_spec.rb +0 -30
  112. data/spec/converter_repository_spec.rb +0 -97
  113. data/spec/converter_spreadsheet_spec.rb +0 -39
  114. data/spec/converter_video_spec.rb +0 -97
  115. data/spec/converter_xsl_spec.rb +0 -56
  116. data/spec/data/Cevennes2.bmp +0 -0
  117. data/spec/data/Cevennes2.jp2 +0 -0
  118. data/spec/data/Cevennes2.ppm +0 -22492
  119. data/spec/data/NikonRaw-CameraRaw.TIF +0 -0
  120. data/spec/data/NikonRaw-CaptureOne.tif +0 -0
  121. data/spec/data/audio/carlin_disappointed.aac +0 -0
  122. data/spec/data/audio/carlin_disappointed.ac3 +0 -0
  123. data/spec/data/audio/carlin_disappointed.aiff +0 -0
  124. data/spec/data/audio/carlin_disappointed.au +0 -0
  125. data/spec/data/audio/carlin_disappointed.flac +0 -0
  126. data/spec/data/audio/carlin_disappointed.m4a +0 -0
  127. data/spec/data/audio/carlin_disappointed.mka +0 -0
  128. data/spec/data/audio/carlin_disappointed.mp3 +0 -0
  129. data/spec/data/audio/carlin_disappointed.ogg +0 -0
  130. data/spec/data/audio/carlin_disappointed.ra +0 -0
  131. data/spec/data/audio/carlin_disappointed.voc +0 -0
  132. data/spec/data/audio/carlin_disappointed.wav +0 -0
  133. data/spec/data/audio/carlin_disappointed.wma +0 -0
  134. data/spec/data/audio/greensleeves.aac +0 -0
  135. data/spec/data/audio/greensleeves.ac3 +0 -0
  136. data/spec/data/audio/greensleeves.aiff +0 -0
  137. data/spec/data/audio/greensleeves.au +0 -0
  138. data/spec/data/audio/greensleeves.flac +0 -0
  139. data/spec/data/audio/greensleeves.m4a +0 -0
  140. data/spec/data/audio/greensleeves.mka +0 -0
  141. data/spec/data/audio/greensleeves.mp3 +0 -0
  142. data/spec/data/audio/greensleeves.ogg +0 -0
  143. data/spec/data/audio/greensleeves.ra +0 -0
  144. data/spec/data/audio/greensleeves.voc +0 -0
  145. data/spec/data/audio/greensleeves.wav +0 -0
  146. data/spec/data/audio/greensleeves.wma +0 -0
  147. data/spec/data/audio/king_nonviolence.aac +0 -0
  148. data/spec/data/audio/king_nonviolence.ac3 +0 -0
  149. data/spec/data/audio/king_nonviolence.aiff +0 -0
  150. data/spec/data/audio/king_nonviolence.au +0 -0
  151. data/spec/data/audio/king_nonviolence.flac +0 -0
  152. data/spec/data/audio/king_nonviolence.m4a +0 -0
  153. data/spec/data/audio/king_nonviolence.mka +0 -0
  154. data/spec/data/audio/king_nonviolence.mp3 +0 -0
  155. data/spec/data/audio/king_nonviolence.ogg +0 -0
  156. data/spec/data/audio/king_nonviolence.ra +0 -0
  157. data/spec/data/audio/king_nonviolence.voc +0 -0
  158. data/spec/data/audio/king_nonviolence.wav +0 -0
  159. data/spec/data/audio/king_nonviolence.wma +0 -0
  160. data/spec/data/audio/top_gun_secret.aac +0 -0
  161. data/spec/data/audio/top_gun_secret.ac3 +0 -0
  162. data/spec/data/audio/top_gun_secret.aiff +0 -0
  163. data/spec/data/audio/top_gun_secret.au +0 -0
  164. data/spec/data/audio/top_gun_secret.flac +0 -0
  165. data/spec/data/audio/top_gun_secret.m4a +0 -0
  166. data/spec/data/audio/top_gun_secret.mka +0 -0
  167. data/spec/data/audio/top_gun_secret.mp3 +0 -0
  168. data/spec/data/audio/top_gun_secret.ogg +0 -0
  169. data/spec/data/audio/top_gun_secret.ra +0 -0
  170. data/spec/data/audio/top_gun_secret.voc +0 -0
  171. data/spec/data/audio/top_gun_secret.wav +0 -0
  172. data/spec/data/audio/top_gun_secret.wma +0 -0
  173. data/spec/data/multipage.tif +0 -0
  174. data/spec/data/multipage.tif.jp2 +0 -0
  175. data/spec/data/test-ead.xml +0 -392
  176. data/spec/data/test-jpg.tif +0 -0
  177. data/spec/data/test-lzw.tif +0 -0
  178. data/spec/data/test-options.jpg +0 -0
  179. data/spec/data/test-options.png +0 -0
  180. data/spec/data/test.bmp +0 -0
  181. data/spec/data/test.doc +0 -0
  182. data/spec/data/test.docx +0 -0
  183. data/spec/data/test.gif +0 -0
  184. data/spec/data/test.jpg +0 -0
  185. data/spec/data/test.ods +0 -0
  186. data/spec/data/test.odt +0 -0
  187. data/spec/data/test.pdf +0 -0
  188. data/spec/data/test.pdf.tif +0 -0
  189. data/spec/data/test.png +0 -0
  190. data/spec/data/test.ps +0 -8631
  191. data/spec/data/test.psd +0 -0
  192. data/spec/data/test.rtf +0 -1455
  193. data/spec/data/test.tif +0 -0
  194. data/spec/data/test.txt +0 -12
  195. data/spec/data/test.xcf +0 -0
  196. data/spec/data/test.xls +0 -0
  197. data/spec/data/test.xlsx +0 -0
  198. data/spec/data/test.xml +0 -4
  199. data/spec/data/test_pdfa.pdf +0 -0
  200. data/spec/data/video/SampleVideo_1080x720_2mb.flv +0 -0
  201. data/spec/data/video/SampleVideo_1080x720_2mb.mkv +0 -0
  202. data/spec/data/video/SampleVideo_1080x720_2mb.mp4 +0 -0
  203. data/spec/data/video/SampleVideo_176x144_2mb.3gp +0 -0
  204. data/spec/data/video/SampleVideo_320x240_2mb.3gp +0 -0
  205. data/spec/data/video/SampleVideo_360x240_2mb.flv +0 -0
  206. data/spec/data/video/SampleVideo_360x240_2mb.mkv +0 -0
  207. data/spec/data/video/SampleVideo_360x240_2mb.mp4 +0 -0
  208. data/spec/data/video/copyright.png +0 -0
  209. data/spec/data/xml/134476_ead.XML +0 -1
  210. data/spec/data/xml/134476_ead.pdf +0 -0
  211. data/spec/data/xml/134476_fo.XML +0 -383
  212. data/spec/data/xml/134476_raw.XML +0 -141
  213. data/spec/data/xml/ead2fo_pdf.xsl +0 -1453
  214. data/spec/data/xml/header_nolink_pdf.xsl +0 -120
  215. data/spec/data/xml/lookupLists.xsl +0 -488
  216. data/spec/data/xml/scope_eadToHTML.xsl +0 -2376
  217. data/spec/data/xml/scope_xmlToEAD_dom.xsl +0 -952
  218. data/spec/identifier_spec.rb +0 -161
  219. data/spec/spec_helper.rb +0 -58
  220. data/spec/test_types.yml +0 -12
  221. data/spec/type_database_spec.rb +0 -140
  222. data/tools/pdfbox/preflight-app-1.8.10.jar +0 -0
@@ -15,7 +15,7 @@ module Libis
15
15
  end
16
16
 
17
17
  def self.output_types(format = nil)
18
- return [] unless input_types.include?(format)
18
+ return [] unless input_types.include?(format) if format
19
19
  [:JP2]
20
20
  end
21
21
 
@@ -91,7 +91,7 @@ module Libis
91
91
 
92
92
 
93
93
  Libis::Tools::Command.run(
94
- Libis::Format::Config[:j2kdriver],
94
+ Libis::Format::Config[:j2k_cmd],
95
95
  '--input-file-name', source,
96
96
  '--set-output-type', 'JP2',
97
97
  *options,
@@ -3,7 +3,7 @@
3
3
  require_relative 'base'
4
4
 
5
5
  require 'libis/format/tool/office_to_pdf'
6
- require 'libis/format/type_database'
6
+ require 'libis/format/library'
7
7
 
8
8
  module Libis
9
9
  module Format
@@ -32,7 +32,7 @@ module Libis
32
32
  end
33
33
 
34
34
  def self.output_types(format = nil)
35
- return [] unless input_types.include?(format)
35
+ return [] unless input_types.include?(format) if format
36
36
  [:PDF]
37
37
  end
38
38
 
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_merge'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ # noinspection DuplicatedCode
12
+ class PdfAssembler < Libis::Format::Converter::Base
13
+
14
+ def self.input_types
15
+ [:PDF]
16
+ end
17
+
18
+ def self.output_types(format = nil)
19
+ return [] unless input_types.include?(format) if format
20
+ [:PDF]
21
+ end
22
+
23
+ def self.category
24
+ :assembler
25
+ end
26
+
27
+ def pdf_assemnble(_)
28
+ #force usage of this converter
29
+ end
30
+
31
+ def convert(source, target, format, opts = {})
32
+ super
33
+
34
+ result = if source.is_a? Array
35
+ assemble(source, target)
36
+ elsif File.directory?(source)
37
+ source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
38
+ assemble(source_list, target)
39
+ else
40
+ assemble([source], target)
41
+ end
42
+ return nil unless result
43
+
44
+ result
45
+ end
46
+
47
+ private
48
+
49
+ def assemble(source, target)
50
+
51
+ result = Libis::Format::Tool::PdfMerge.run(source, target)
52
+
53
+ unless result[:err].empty?
54
+ error("PdfMerge encountered errors:\n%s", result[:err].join(join("\n")))
55
+ return nil
56
+ end
57
+
58
+ target
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
@@ -11,6 +11,7 @@ module Libis
11
11
  module Format
12
12
  module Converter
13
13
 
14
+ # noinspection DuplicatedCode
14
15
  class PdfConverter < Libis::Format::Converter::Base
15
16
 
16
17
  def self.input_types
@@ -18,84 +19,34 @@ module Libis
18
19
  end
19
20
 
20
21
  def self.output_types(format = nil)
21
- return [] unless input_types.include?(format)
22
+ return [] unless input_types.include?(format) if format
22
23
  [:PDF, :PDFA]
23
24
  end
24
25
 
25
- def pdf_convert(_)
26
- #force usage of this converter
26
+ def title(v)
27
+ @options[:title] = v.blank? ? nil : v
27
28
  end
28
29
 
29
- # Set metadata for Pdf file
30
- #
31
- # valid metadata keys are):
32
- # - title
33
- # - author
34
- # - creator
35
- # - keywords
36
- # - subject
37
- #
38
- # @param [Hash] values list of metadata values to set
39
- def metadata(values = {})
40
- values.key_strings_to_symbols!
41
- values.each do |k, v|
42
- next unless [:title, :author, :creator, :keywords, :subject].include?(k)
43
- @options["md_#{k}"] = v
44
- end
30
+ def author(v)
31
+ @options[:author] = v.blank? ? nil : v
45
32
  end
46
33
 
47
- # Select a partial list of pages
48
- # @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
49
- def range(selection)
50
- @options[:ranges] = selection
34
+ def creator(v)
35
+ @options[:creator] = v.blank? ? nil : v
51
36
  end
52
37
 
53
- # Create or use a watermark image.
54
- #
55
- # The watermark options are (use symbols):
56
- # - text: text to create a watermark from
57
- # - file: watermark image to use
58
- # - rotation: rotation of the watermark text (in degrees; integer number)
59
- # - size: font size of the watermark text
60
- # - opacity: opacity of the watermark (fraction 0.0 - 1.0)
61
- # - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch). Fractions are percentage of widht/height.
62
- # If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
63
- # file will be created or overwritten with a newly created watermark image.
64
- #
65
- # The created watermark file will be a PNG image with transparent background containing the supplied text
66
- # slanted by 30 degrees counter-clockwise.
67
- #
68
- # @param [Hash] options Hash of options for watermark creation.
69
- def watermark(options = {})
70
- options.key_strings_to_symbols!
71
- if options[:file] && File.exist?(options[:file])
72
- @options['wm_image'] = options[:file]
73
- else
74
- @options['wm_text'] = (options[:text] || '© LIBIS').split('\n')
75
- @options['wm_text_rotation'] = options[:rotation] if options[:rotation]
76
- @options['wm_font_size'] = options[:size] if options[:size]
77
- end
78
- @options['wm_opacity'] = options[:opacity] || '0.3'
79
- @options['wm_gap_ratio'] = options[:gap] if options[:gap].to_s =~ /^\s*(0+\.\d+|1\.0+)\s*$/
80
- @options['wm_gap_size'] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
38
+ def keywords(v)
39
+ @options[:keywords] = v.blank? ? nil : v
81
40
  end
82
41
 
83
- # Optimize the PDF
84
- #
85
- # This reduces the graphics quality to a level in order to limit file size. This option relies on the
86
- # presence of ghostscript and takes one argument: the quality level. It should be one of:
87
- #
88
- # - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
89
- # - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
90
- # - 2 : good quality
91
- # - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
92
- # - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
93
- #
94
- # Note that the optimization is intended to be used with PDF's containing high-resolution images.
95
- #
96
- # @param [Integer] setting quality setting. [0-4]
97
- def optimize(setting = 1)
98
- @options['optimize'] = %w(screen ebook default printer prepress)[setting] if (0..4) === setting
42
+ def subject(v)
43
+ @options[:subject] = v.blank? ? nil : v
44
+ end
45
+
46
+ # Select a partial list of pages
47
+ # @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
48
+ def range(selection)
49
+ @options[:ranges] = selection.blank? ? nil : selection
99
50
  end
100
51
 
101
52
  def convert(source, target, format, opts = {})
@@ -103,12 +54,6 @@ module Libis
103
54
 
104
55
  result = nil
105
56
 
106
- if (quality = @options.delete('optimize'))
107
- result = optimize_pdf(source, target, quality)
108
- return nil unless result
109
- source = result
110
- end
111
-
112
57
  unless @options.empty?
113
58
  result = convert_pdf(source, target)
114
59
  return nil unless result
@@ -123,32 +68,29 @@ module Libis
123
68
 
124
69
  end
125
70
 
126
- def optimize_pdf(source, target, quality)
127
-
128
- using_temp(target) do |tmpname|
129
- result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
130
- unless result[:status] == 0
131
- error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join('\n'))
132
- next nil
133
- end
134
- tmpname
135
- end
136
- end
71
+ OPTIONS_TABLE = {
72
+ title: 'md_title',
73
+ author: 'md_author',
74
+ creator: 'md_creator',
75
+ keywords: 'md_keywords',
76
+ subject: 'md_subject'
77
+ }
137
78
 
138
79
  def convert_pdf(source, target)
139
80
 
140
81
  using_temp(target) do |tmpname|
141
82
  result = Libis::Format::Tool::PdfCopy.run(
142
83
  source, tmpname,
143
- @options.map { |k, v|
84
+ @options.map {|k, v|
144
85
  if v.nil?
145
86
  nil
146
87
  else
88
+ k = OPTIONS_TABLE[k] || k
147
89
  ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
148
- end }.flatten
90
+ end}.compact.flatten
149
91
  )
150
92
  unless result[:err].empty?
151
- error("Pdf conversion encountered errors:\n%s", result[:err].join('\n'))
93
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
152
94
  next nil
153
95
  end
154
96
  tmpname
@@ -160,9 +102,11 @@ module Libis
160
102
 
161
103
  using_temp(target) do |tmpname|
162
104
  result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
163
- unless result[:status] == 0
164
- error("Pdf/A conversion encountered errors:\n%s", result[:err].join('\n'))
105
+ if result[:status] != 0
106
+ error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
165
107
  next nil
108
+ else
109
+ warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
166
110
  end
167
111
  tmpname
168
112
  end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/tools/extend/hash'
6
+ require 'libis/format/tool/pdf_copy'
7
+ require 'libis/format/tool/pdf_to_pdfa'
8
+ require 'libis/format/tool/pdf_optimizer'
9
+
10
+ module Libis
11
+ module Format
12
+ module Converter
13
+
14
+ class PdfOptimizer < Libis::Format::Converter::Base
15
+
16
+ def self.input_types
17
+ [:PDF]
18
+ end
19
+
20
+ def self.output_types(format = nil)
21
+ return [] unless input_types.include?(format) if format
22
+ [:PDF]
23
+ end
24
+
25
+ def pdf_optimize(_)
26
+ #force usage of this converter
27
+ end
28
+
29
+ # Optimize the PDF
30
+ #
31
+ # This reduces the graphics quality to a level in order to limit file size. This option relies on the
32
+ # presence of ghostscript and takes one argument: the quality level. It should be one of:
33
+ #
34
+ # - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
35
+ # - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
36
+ # - 2 : good quality
37
+ # - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
38
+ # - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
39
+ #
40
+ # Note that the optimization is intended to be used with PDF's containing high-resolution images.
41
+ #
42
+ # @param [Integer] setting quality setting. [0-4]
43
+ def quality(setting = 1)
44
+ @quality = %w(screen ebook default printer prepress)[setting] if (0..4) === setting
45
+ end
46
+
47
+ def convert(source, target, format, opts = {})
48
+ super
49
+
50
+ optimize_pdf(source, target, @quality || 'ebook')
51
+
52
+ end
53
+
54
+ def optimize_pdf(source, target, quality)
55
+
56
+ using_temp(target) do |tmpname|
57
+ result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
58
+ unless result[:status] == 0
59
+ error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
60
+ next nil
61
+ end
62
+ tmpname
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_split'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ # noinspection DuplicatedCode
12
+ class PdfSplitter < Libis::Format::Converter::Base
13
+
14
+ def self.input_types
15
+ [:PDF]
16
+ end
17
+
18
+ def self.output_types(format = nil)
19
+ return [] unless input_types.include?(format) if format
20
+ [:PDF]
21
+ end
22
+
23
+ def pdf_split(_)
24
+ #force usage of this converter
25
+ end
26
+
27
+ def self.category
28
+ :splitter
29
+ end
30
+
31
+ # Split at given page. If omitted or nil, the source PDF will be split at every page
32
+ def page(v)
33
+ @page = v unless v.blank
34
+ end
35
+
36
+ def convert(source, target, format, opts = {})
37
+ super
38
+
39
+ result = split(source, target)
40
+ return nil unless result
41
+
42
+ result
43
+ end
44
+
45
+ private
46
+
47
+ def split(source, target)
48
+
49
+ options = @page ? ['--page', @page] : ['--every_page']
50
+ using_temp(target) do |tmpname|
51
+ result = Libis::Format::Tool::PdfSplit.run(source, tmpname, *options)
52
+ unless result[:err].empty?
53
+ error("Pdf split encountered errors:\n%s", result[:err].join(join("\n")))
54
+ next nil
55
+ end
56
+ tmpname
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,110 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/tools/extend/hash'
6
+ require 'libis/format/tool/pdf_copy'
7
+ require 'libis/format/tool/pdf_to_pdfa'
8
+ require 'libis/format/tool/pdf_optimizer'
9
+
10
+ module Libis
11
+ module Format
12
+ module Converter
13
+
14
+ class PdfWatermarker < Libis::Format::Converter::Base
15
+
16
+ def self.input_types
17
+ [:PDF]
18
+ end
19
+
20
+ def self.output_types(format = nil)
21
+ return [] unless input_types.include?(format) if format
22
+ [:PDF]
23
+ end
24
+
25
+ def pdf_watermark(_)
26
+ #force usage of this converter
27
+ end
28
+
29
+ def initialize
30
+ super
31
+ @options[:text] = '© LIBIS'
32
+ @options[:opacity] = '0.3'
33
+ end
34
+
35
+ def file(v)
36
+ @options[:file] = v.blank? ? nil : v
37
+ end
38
+
39
+ def text(v)
40
+ @options[:text] = v
41
+ end
42
+
43
+ def rotation(v)
44
+ @options[:rotation] = v unless v.blank?
45
+ end
46
+
47
+ def size(v)
48
+ @options[:size] = v unless v.blank?
49
+ end
50
+
51
+ def opacity(v)
52
+ @options[:opacity] = v unless v.blank?
53
+ end
54
+
55
+ def gap_size(v)
56
+ @options[:gap_size] = v
57
+ end
58
+
59
+ def gap_ratio(v)
60
+ @options[:gap_ratio] = v
61
+ end
62
+
63
+ def convert(source, target, format, opts = {})
64
+ super
65
+
66
+ result = convert_pdf(source, target)
67
+ return nil unless result
68
+
69
+ result
70
+
71
+ end
72
+
73
+ OPTIONS_TABLE = {
74
+ file: 'wm_image',
75
+ text: 'wm_text',
76
+ rotation: 'wm_text_rotation',
77
+ size: 'wm_font_size',
78
+ opacity: 'wm_opacity',
79
+ gap_size: 'wm_gap_size',
80
+ gap_ratio: 'wm_gap_ratio'
81
+ }
82
+ # noinspection DuplicatedCode
83
+ def convert_pdf(source, target)
84
+
85
+ using_temp(target) do |tmpname|
86
+ result = Libis::Format::Tool::PdfCopy.run(
87
+ source, tmpname,
88
+ @options.map {|k, v|
89
+ if v.nil?
90
+ nil
91
+ else
92
+ v = v.split('\n') unless v.blank? if k == :text
93
+ k = OPTIONS_TABLE[k] || k
94
+ ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
95
+ end}.compact.flatten
96
+ )
97
+ unless result[:err].empty?
98
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
99
+ next nil
100
+ end
101
+ tmpname
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+ end
110
+ end