libis-format 1.0.4 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +5 -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/docker_cfg.yml +1 -0
  10. data/lib/libis/format.rb +12 -3
  11. data/lib/libis/format/cli/convert.rb +4 -4
  12. data/lib/libis/format/config.rb +15 -10
  13. data/lib/libis/format/converter/audio_converter.rb +3 -37
  14. data/lib/libis/format/converter/base.rb +22 -8
  15. data/lib/libis/format/converter/chain.rb +3 -3
  16. data/lib/libis/format/converter/image_assembler.rb +82 -0
  17. data/lib/libis/format/converter/image_converter.rb +20 -138
  18. data/lib/libis/format/converter/image_splitter.rb +84 -0
  19. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  20. data/lib/libis/format/converter/jp2_converter.rb +2 -2
  21. data/lib/libis/format/converter/office_converter.rb +2 -2
  22. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  23. data/lib/libis/format/converter/pdf_converter.rb +10 -134
  24. data/lib/libis/format/converter/pdf_metadata.rb +82 -0
  25. data/lib/libis/format/converter/pdf_optimizer.rb +67 -0
  26. data/lib/libis/format/converter/pdf_protecter.rb +147 -0
  27. data/lib/libis/format/converter/pdf_selecter.rb +83 -0
  28. data/lib/libis/format/converter/pdf_splitter.rb +70 -0
  29. data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
  30. data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
  31. data/lib/libis/format/converter/pdf_watermarker_text.rb +93 -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 +3 -3
  35. data/lib/libis/format/info.rb +27 -0
  36. data/lib/libis/format/library.rb +147 -0
  37. data/lib/libis/format/tool.rb +4 -1
  38. data/lib/libis/format/tool/droid.rb +2 -2
  39. data/lib/libis/format/tool/extension_identification.rb +4 -4
  40. data/lib/libis/format/tool/ffmpeg.rb +1 -1
  41. data/lib/libis/format/tool/fido.rb +1 -1
  42. data/lib/libis/format/tool/fop_pdf.rb +1 -1
  43. data/lib/libis/format/tool/identification_tool.rb +6 -6
  44. data/lib/libis/format/tool/office_to_pdf.rb +1 -1
  45. data/lib/libis/format/tool/pdf_merge.rb +4 -4
  46. data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +6 -6
  47. data/lib/libis/format/tool/pdf_protect.rb +47 -0
  48. data/lib/libis/format/tool/pdf_select.rb +47 -0
  49. data/lib/libis/format/tool/pdf_split.rb +5 -5
  50. data/lib/libis/format/tool/pdf_to_pdfa.rb +1 -2
  51. data/lib/libis/format/tool/pdf_watermark.rb +47 -0
  52. data/lib/libis/format/tool/pdfa_validator.rb +3 -4
  53. data/lib/libis/format/tool/spreadsheet_to_ods.rb +2 -1
  54. data/lib/libis/format/version.rb +1 -1
  55. data/lib/libis/format/yaml_loader.rb +71 -0
  56. data/libis-format.gemspec +5 -4
  57. data/tools/PdfTool.jar +0 -0
  58. data/tools/bcpkix-jdk15on-167.jar +0 -0
  59. data/tools/bcprov-jdk15on-167.jar +0 -0
  60. data/tools/fop/build/fop.jar +0 -0
  61. data/tools/fop/conf/fop.xconf +466 -0
  62. data/tools/fop/fop +258 -0
  63. data/tools/fop/fop.bat +75 -0
  64. data/tools/fop/fop.cmd +31 -0
  65. data/tools/fop/fop.js +341 -0
  66. data/tools/fop/lib/README.txt +243 -0
  67. data/tools/fop/lib/avalon-framework-api-4.3.1.jar +0 -0
  68. data/tools/fop/lib/avalon-framework-impl-4.3.1.jar +0 -0
  69. data/tools/fop/lib/avalon-framework.LICENSE.txt +175 -0
  70. data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -0
  71. data/tools/fop/lib/batik-all-1.10.jar +0 -0
  72. data/tools/fop/lib/batik.LICENSE.txt +201 -0
  73. data/tools/fop/lib/batik.NOTICE.txt +18 -0
  74. data/tools/fop/lib/commons-io-1.3.1.jar +0 -0
  75. data/tools/fop/lib/commons-io.LICENSE.txt +203 -0
  76. data/tools/fop/lib/commons-io.NOTICE.txt +6 -0
  77. data/tools/fop/lib/commons-logging-1.0.4.jar +0 -0
  78. data/tools/fop/lib/commons-logging.LICENSE.txt +202 -0
  79. data/tools/fop/lib/commons-logging.NOTICE.txt +3 -0
  80. data/tools/fop/lib/fontbox-2.0.7.jar +0 -0
  81. data/tools/fop/lib/serializer-2.7.2.jar +0 -0
  82. data/tools/fop/lib/serializer.LICENSE.txt +201 -0
  83. data/tools/fop/lib/serializer.NOTICE.txt +15 -0
  84. data/tools/fop/lib/xalan-2.7.2.jar +0 -0
  85. data/tools/fop/lib/xalan.BCEL.LICENSE.txt +52 -0
  86. data/tools/fop/lib/xalan.LICENSE.txt +202 -0
  87. data/tools/fop/lib/xalan.NOTICE.txt +44 -0
  88. data/tools/fop/lib/xalan.regexp.LICENSE.txt +52 -0
  89. data/tools/fop/lib/xalan.runtime.LICENSE.txt +20 -0
  90. data/tools/fop/lib/xerces.LICENSE.txt +56 -0
  91. data/tools/fop/lib/xercesImpl-2.9.1.jar +0 -0
  92. data/tools/fop/lib/xercesImpl.LICENSE.txt +201 -0
  93. data/tools/fop/lib/xercesImpl.NOTICE.txt +14 -0
  94. data/tools/fop/lib/xml-apis-1.3.04.jar +0 -0
  95. data/tools/fop/lib/xml-apis-ext-1.3.04.jar +0 -0
  96. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-documentation.txt +73 -0
  97. data/tools/fop/lib/xml-apis-ext.LICENSE.dom-software.txt +61 -0
  98. data/tools/fop/lib/xml-apis-ext.LICENSE.sac.html +75 -0
  99. data/tools/fop/lib/xml-apis-ext.LICENSE.txt +202 -0
  100. data/tools/fop/lib/xml-apis-ext.NOTICE.txt +16 -0
  101. data/tools/fop/lib/xml-apis-ext.README.dom.txt +56 -0
  102. data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -0
  103. data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -0
  104. data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -0
  105. data/tools/fop/lib/xml-apis.LICENSE.txt +201 -0
  106. data/tools/fop/lib/xml-apis.NOTICE.txt +13 -0
  107. data/tools/fop/lib/xmlgraphics-commons-2.3.jar +0 -0
  108. data/tools/fop/lib/xmlgraphics-commons.LICENSE.txt +202 -0
  109. data/tools/fop/lib/xmlgraphics-commons.NOTICE.txt +5 -0
  110. data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
  111. data/tools/pdfbox/{pdfbox-app-1.8.10.jar → preflight-app-2.0.13.jar} +0 -0
  112. metadata +86 -246
  113. data/lib/libis/format/type_database.rb +0 -134
  114. data/lib/libis/format/type_database_impl.rb +0 -120
  115. data/spec/converter_audio_spec.rb +0 -66
  116. data/spec/converter_fop_spec.rb +0 -37
  117. data/spec/converter_image_spec.rb +0 -166
  118. data/spec/converter_office_spec.rb +0 -84
  119. data/spec/converter_pdf_spec.rb +0 -30
  120. data/spec/converter_repository_spec.rb +0 -97
  121. data/spec/converter_spreadsheet_spec.rb +0 -39
  122. data/spec/converter_video_spec.rb +0 -97
  123. data/spec/converter_xsl_spec.rb +0 -56
  124. data/spec/data/Cevennes2.bmp +0 -0
  125. data/spec/data/Cevennes2.jp2 +0 -0
  126. data/spec/data/Cevennes2.ppm +0 -22492
  127. data/spec/data/NikonRaw-CameraRaw.TIF +0 -0
  128. data/spec/data/NikonRaw-CaptureOne.tif +0 -0
  129. data/spec/data/audio/carlin_disappointed.aac +0 -0
  130. data/spec/data/audio/carlin_disappointed.ac3 +0 -0
  131. data/spec/data/audio/carlin_disappointed.aiff +0 -0
  132. data/spec/data/audio/carlin_disappointed.au +0 -0
  133. data/spec/data/audio/carlin_disappointed.flac +0 -0
  134. data/spec/data/audio/carlin_disappointed.m4a +0 -0
  135. data/spec/data/audio/carlin_disappointed.mka +0 -0
  136. data/spec/data/audio/carlin_disappointed.mp3 +0 -0
  137. data/spec/data/audio/carlin_disappointed.ogg +0 -0
  138. data/spec/data/audio/carlin_disappointed.ra +0 -0
  139. data/spec/data/audio/carlin_disappointed.voc +0 -0
  140. data/spec/data/audio/carlin_disappointed.wav +0 -0
  141. data/spec/data/audio/carlin_disappointed.wma +0 -0
  142. data/spec/data/audio/greensleeves.aac +0 -0
  143. data/spec/data/audio/greensleeves.ac3 +0 -0
  144. data/spec/data/audio/greensleeves.aiff +0 -0
  145. data/spec/data/audio/greensleeves.au +0 -0
  146. data/spec/data/audio/greensleeves.flac +0 -0
  147. data/spec/data/audio/greensleeves.m4a +0 -0
  148. data/spec/data/audio/greensleeves.mka +0 -0
  149. data/spec/data/audio/greensleeves.mp3 +0 -0
  150. data/spec/data/audio/greensleeves.ogg +0 -0
  151. data/spec/data/audio/greensleeves.ra +0 -0
  152. data/spec/data/audio/greensleeves.voc +0 -0
  153. data/spec/data/audio/greensleeves.wav +0 -0
  154. data/spec/data/audio/greensleeves.wma +0 -0
  155. data/spec/data/audio/king_nonviolence.aac +0 -0
  156. data/spec/data/audio/king_nonviolence.ac3 +0 -0
  157. data/spec/data/audio/king_nonviolence.aiff +0 -0
  158. data/spec/data/audio/king_nonviolence.au +0 -0
  159. data/spec/data/audio/king_nonviolence.flac +0 -0
  160. data/spec/data/audio/king_nonviolence.m4a +0 -0
  161. data/spec/data/audio/king_nonviolence.mka +0 -0
  162. data/spec/data/audio/king_nonviolence.mp3 +0 -0
  163. data/spec/data/audio/king_nonviolence.ogg +0 -0
  164. data/spec/data/audio/king_nonviolence.ra +0 -0
  165. data/spec/data/audio/king_nonviolence.voc +0 -0
  166. data/spec/data/audio/king_nonviolence.wav +0 -0
  167. data/spec/data/audio/king_nonviolence.wma +0 -0
  168. data/spec/data/audio/top_gun_secret.aac +0 -0
  169. data/spec/data/audio/top_gun_secret.ac3 +0 -0
  170. data/spec/data/audio/top_gun_secret.aiff +0 -0
  171. data/spec/data/audio/top_gun_secret.au +0 -0
  172. data/spec/data/audio/top_gun_secret.flac +0 -0
  173. data/spec/data/audio/top_gun_secret.m4a +0 -0
  174. data/spec/data/audio/top_gun_secret.mka +0 -0
  175. data/spec/data/audio/top_gun_secret.mp3 +0 -0
  176. data/spec/data/audio/top_gun_secret.ogg +0 -0
  177. data/spec/data/audio/top_gun_secret.ra +0 -0
  178. data/spec/data/audio/top_gun_secret.voc +0 -0
  179. data/spec/data/audio/top_gun_secret.wav +0 -0
  180. data/spec/data/audio/top_gun_secret.wma +0 -0
  181. data/spec/data/multipage.tif +0 -0
  182. data/spec/data/multipage.tif.jp2 +0 -0
  183. data/spec/data/test-ead.xml +0 -392
  184. data/spec/data/test-jpg.tif +0 -0
  185. data/spec/data/test-lzw.tif +0 -0
  186. data/spec/data/test-options.jpg +0 -0
  187. data/spec/data/test-options.png +0 -0
  188. data/spec/data/test.bmp +0 -0
  189. data/spec/data/test.doc +0 -0
  190. data/spec/data/test.docx +0 -0
  191. data/spec/data/test.gif +0 -0
  192. data/spec/data/test.jpg +0 -0
  193. data/spec/data/test.ods +0 -0
  194. data/spec/data/test.odt +0 -0
  195. data/spec/data/test.pdf +0 -0
  196. data/spec/data/test.pdf.tif +0 -0
  197. data/spec/data/test.png +0 -0
  198. data/spec/data/test.ps +0 -8631
  199. data/spec/data/test.psd +0 -0
  200. data/spec/data/test.rtf +0 -1455
  201. data/spec/data/test.tif +0 -0
  202. data/spec/data/test.txt +0 -12
  203. data/spec/data/test.xcf +0 -0
  204. data/spec/data/test.xls +0 -0
  205. data/spec/data/test.xlsx +0 -0
  206. data/spec/data/test.xml +0 -4
  207. data/spec/data/test_pdfa.pdf +0 -0
  208. data/spec/data/video/SampleVideo_1080x720_2mb.flv +0 -0
  209. data/spec/data/video/SampleVideo_1080x720_2mb.mkv +0 -0
  210. data/spec/data/video/SampleVideo_1080x720_2mb.mp4 +0 -0
  211. data/spec/data/video/SampleVideo_176x144_2mb.3gp +0 -0
  212. data/spec/data/video/SampleVideo_320x240_2mb.3gp +0 -0
  213. data/spec/data/video/SampleVideo_360x240_2mb.flv +0 -0
  214. data/spec/data/video/SampleVideo_360x240_2mb.mkv +0 -0
  215. data/spec/data/video/SampleVideo_360x240_2mb.mp4 +0 -0
  216. data/spec/data/video/copyright.png +0 -0
  217. data/spec/data/xml/134476_ead.XML +0 -1
  218. data/spec/data/xml/134476_ead.pdf +0 -0
  219. data/spec/data/xml/134476_fo.XML +0 -383
  220. data/spec/data/xml/134476_raw.XML +0 -141
  221. data/spec/data/xml/ead2fo_pdf.xsl +0 -1453
  222. data/spec/data/xml/header_nolink_pdf.xsl +0 -120
  223. data/spec/data/xml/lookupLists.xsl +0 -488
  224. data/spec/data/xml/scope_eadToHTML.xsl +0 -2376
  225. data/spec/data/xml/scope_xmlToEAD_dom.xsl +0 -952
  226. data/spec/identifier_spec.rb +0 -161
  227. data/spec/spec_helper.rb +0 -58
  228. data/spec/test_types.yml +0 -12
  229. data/spec/type_database_spec.rb +0 -140
  230. data/tools/bcpkix-jdk15on-1.49.jar +0 -0
  231. data/tools/bcprov-jdk15on-1.49.jar +0 -0
  232. 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
@@ -2,15 +2,13 @@
2
2
 
3
3
  require_relative 'base'
4
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'
5
+ require 'libis/format/tool/pdf_metadata'
9
6
 
10
7
  module Libis
11
8
  module Format
12
9
  module Converter
13
10
 
11
+ # noinspection DuplicatedCode
14
12
  class PdfConverter < Libis::Format::Converter::Base
15
13
 
16
14
  def self.input_types
@@ -18,151 +16,29 @@ module Libis
18
16
  end
19
17
 
20
18
  def self.output_types(format = nil)
21
- return [] unless input_types.include?(format)
22
- [:PDF, :PDFA]
23
- end
24
-
25
- def pdf_convert(_)
26
- #force usage of this converter
27
- end
28
-
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
45
- end
46
-
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
51
- end
52
-
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*$/
81
- end
82
-
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
19
+ return [] unless input_types.include?(format) if format
20
+ [:PDFA]
99
21
  end
100
22
 
101
23
  def convert(source, target, format, opts = {})
102
24
  super
103
25
 
104
- result = nil
105
-
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
- unless @options.empty?
113
- result = convert_pdf(source, target)
114
- return nil unless result
115
- source = result
116
- end
117
-
118
- if format == :PDFA and source
119
- result = pdf_to_pdfa(source, target)
120
- end
26
+ result = pdf_to_pdfa(source, target)
27
+ return nil unless result
121
28
 
122
29
  result
123
30
 
124
31
  end
125
32
 
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
137
-
138
- def convert_pdf(source, target)
139
-
140
- using_temp(target) do |tmpname|
141
- result = Libis::Format::Tool::PdfCopy.run(
142
- source, tmpname,
143
- @options.map { |k, v|
144
- if v.nil?
145
- nil
146
- else
147
- ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
148
- end }.flatten
149
- )
150
- unless result[:err].empty?
151
- error("Pdf conversion encountered errors:\n%s", result[:err].join('\n'))
152
- next nil
153
- end
154
- tmpname
155
- end
156
-
157
- end
158
-
159
33
  def pdf_to_pdfa(source, target)
160
34
 
161
35
  using_temp(target) do |tmpname|
162
36
  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'))
37
+ if result[:status] != 0
38
+ error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
165
39
  next nil
40
+ else
41
+ warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
166
42
  end
167
43
  tmpname
168
44
  end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_metadata'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ # noinspection DuplicatedCode
12
+ class PdfMetadata < 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 title(v)
24
+ @options[:title] = v.blank? ? nil : v
25
+ end
26
+
27
+ def author(v)
28
+ @options[:author] = v.blank? ? nil : v
29
+ end
30
+
31
+ def creator(v)
32
+ @options[:creator] = v.blank? ? nil : v
33
+ end
34
+
35
+ def keywords(v)
36
+ @options[:keywords] = v.blank? ? nil : v
37
+ end
38
+
39
+ def subject(v)
40
+ @options[:subject] = v.blank? ? nil : v
41
+ end
42
+
43
+ def convert(source, target, format, opts = {})
44
+ super
45
+
46
+ result = nil
47
+
48
+ unless @options.empty?
49
+ result = convert_pdf(source, target)
50
+ return nil unless result
51
+ end
52
+
53
+ result
54
+
55
+ end
56
+
57
+ def convert_pdf(source, target)
58
+
59
+ using_temp(target) do |tmpname|
60
+ result = Libis::Format::Tool::PdfMetadata.run(
61
+ source, tmpname,
62
+ @options.map {|k, v|
63
+ if v.nil?
64
+ nil
65
+ else
66
+ ["--#{k}", v]
67
+ end}.compact.flatten
68
+ )
69
+ unless result[:err].empty?
70
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
71
+ next nil
72
+ end
73
+ tmpname
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_optimizer'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ class PdfOptimizer < Libis::Format::Converter::Base
12
+
13
+ def self.input_types
14
+ [:PDF]
15
+ end
16
+
17
+ def self.output_types(format = nil)
18
+ return [] unless input_types.include?(format) if format
19
+ [:PDF]
20
+ end
21
+
22
+ def pdf_optimize(_)
23
+ #force usage of this converter
24
+ end
25
+
26
+ # Optimize the PDF
27
+ #
28
+ # This reduces the graphics quality to a level in order to limit file size. This option relies on the
29
+ # presence of ghostscript and takes one argument: the quality level. It should be one of:
30
+ #
31
+ # - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
32
+ # - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
33
+ # - 2 : good quality
34
+ # - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
35
+ # - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
36
+ #
37
+ # Note that the optimization is intended to be used with PDF's containing high-resolution images.
38
+ #
39
+ # @param [Integer] setting quality setting. [0-4]
40
+ def quality(setting = 1)
41
+ @quality = %w(screen ebook default printer prepress)[setting] if (0..4) === setting
42
+ end
43
+
44
+ def convert(source, target, format, opts = {})
45
+ super
46
+
47
+ optimize_pdf(source, target, @quality || 'ebook')
48
+
49
+ end
50
+
51
+ def optimize_pdf(source, target, quality)
52
+
53
+ using_temp(target) do |tmpname|
54
+ result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
55
+ unless result[:status] == 0
56
+ error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
57
+ next nil
58
+ end
59
+ tmpname
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,147 @@
1
+ # encoding: utf-8
2
+ require 'securerandom'
3
+
4
+ require_relative 'base'
5
+ require 'libis/format/tool/pdf_protect'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ RANDOM_CHARS = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map(&:to_a).flatten
12
+
13
+ # noinspection DuplicatedCode
14
+ class PdfProtecter < 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, :PDFA]
23
+ end
24
+
25
+ def pdf_protect(_)
26
+ #force usage of this converter
27
+ end
28
+
29
+ def initialize
30
+ super
31
+ @options[:edit_password] = SecureRandom.urlsafe_base64(31)
32
+ end
33
+
34
+ def edit_password(pwd)
35
+ @options[:edit_password] = pwd
36
+ end
37
+
38
+ def open_password(pwd)
39
+ @options[:open_password] = pwd
40
+ end
41
+
42
+ def assist(v)
43
+ @flags[:assist] = !!v
44
+ end
45
+
46
+ def copy(v)
47
+ @flags[:copy] = !!v
48
+ end
49
+
50
+ def print(v)
51
+ @flags[:print] = !!v
52
+ end
53
+
54
+ def comments(v)
55
+ @flags[:comments] = !!v
56
+ end
57
+
58
+ def fillin(v)
59
+ @flags[:fillin] = !!v
60
+ end
61
+
62
+ def manage(v)
63
+ @flags[:manage] = !!v
64
+ end
65
+
66
+ def edit(v)
67
+ @flags[:edit] = !!v
68
+ end
69
+
70
+ def convert(source, target, format, opts = {})
71
+ super
72
+
73
+ result = nil
74
+
75
+ unless @options.empty?
76
+ result = convert_pdf(source, target)
77
+ return nil unless result
78
+ source = result
79
+ end
80
+
81
+ if format == :PDFA and source
82
+ result = pdf_to_pdfa(source, target)
83
+ end
84
+
85
+ result
86
+
87
+ end
88
+
89
+ OPTIONS_TABLE = {
90
+ edit_password: 'edit-password',
91
+ open_password: 'open-password',
92
+ fillin: 'fill-in',
93
+ }
94
+
95
+ def convert_pdf(source, target)
96
+
97
+ using_temp(target) do |tmpname|
98
+ result = Libis::Format::Tool::PdfProtect.run(
99
+ source, tmpname,
100
+ [
101
+ @options.map { |k, v|
102
+ if v.nil?
103
+ nil
104
+ else
105
+ k = OPTIONS_TABLE[k] || k
106
+ ["--#{k}", v]
107
+ end
108
+ },
109
+ @flags.map { |k, v|
110
+ if !v
111
+ nil
112
+ else
113
+ k = OPTIONS_TABLE[k] || k
114
+ "--#{k}"
115
+ end
116
+ }
117
+ ].compact.flatten
118
+ )
119
+ unless result[:err].empty?
120
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
121
+ next nil
122
+ end
123
+ tmpname
124
+ end
125
+
126
+ end
127
+
128
+ def pdf_to_pdfa(source, target)
129
+
130
+ using_temp(target) do |tmpname|
131
+ result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
132
+ if result[:status] != 0
133
+ error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
134
+ next nil
135
+ else
136
+ warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
137
+ end
138
+ tmpname
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+ end
147
+ end