pdf4me 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +0 -0
  3. data/README.md +246 -15
  4. data/lib/pdf4me.rb +30 -0
  5. data/lib/pdf4me/actions/complex_action.rb +5 -0
  6. data/lib/pdf4me/actions/convert_file_to_pdf.rb +3 -1
  7. data/lib/pdf4me/actions/convert_to_pdf.rb +1 -5
  8. data/lib/pdf4me/actions/create_images.rb +10 -0
  9. data/lib/pdf4me/actions/create_pdf_a.rb +0 -0
  10. data/lib/pdf4me/actions/create_thumbnail.rb +3 -1
  11. data/lib/pdf4me/actions/extract.rb +10 -0
  12. data/lib/pdf4me/actions/extract_pages.rb +4 -2
  13. data/lib/pdf4me/actions/merge.rb +35 -0
  14. data/lib/pdf4me/actions/merge_two_pdfs.rb +5 -4
  15. data/lib/pdf4me/actions/optimize.rb +0 -0
  16. data/lib/pdf4me/actions/optimize_by_profile.rb +3 -1
  17. data/lib/pdf4me/actions/pdf_a.rb +10 -0
  18. data/lib/pdf4me/actions/split.rb +10 -0
  19. data/lib/pdf4me/actions/split_by_page_nr.rb +0 -0
  20. data/lib/pdf4me/actions/stamp.rb +10 -0
  21. data/lib/pdf4me/actions/text_stamp.rb +9 -2
  22. data/lib/pdf4me/actions/wrapper_action.rb +0 -0
  23. data/lib/pdf4me/client.rb +0 -0
  24. data/lib/pdf4me/configuration.rb +0 -0
  25. data/lib/pdf4me/exceptions.rb +0 -0
  26. data/lib/pdf4me/models/base.rb +5 -1
  27. data/lib/pdf4me/models/color.rb +10 -0
  28. data/lib/pdf4me/models/convert_to_pdf_action.rb +0 -0
  29. data/lib/pdf4me/models/convert_to_pdf_res.rb +2 -1
  30. data/lib/pdf4me/models/create_images_res.rb +9 -0
  31. data/lib/pdf4me/models/custom_cms_config.rb +23 -0
  32. data/lib/pdf4me/models/doc_log.rb +0 -0
  33. data/lib/pdf4me/models/doc_metadata.rb +0 -0
  34. data/lib/pdf4me/models/document.rb +0 -0
  35. data/lib/pdf4me/models/extract_action.rb +28 -0
  36. data/lib/pdf4me/models/extract_res.rb +9 -0
  37. data/lib/pdf4me/models/image.rb +11 -0
  38. data/lib/pdf4me/models/image_action.rb +110 -0
  39. data/lib/pdf4me/models/merge_action.rb +8 -0
  40. data/lib/pdf4me/models/merge_res.rb +8 -0
  41. data/lib/pdf4me/models/notification.rb +1 -1
  42. data/lib/pdf4me/models/optimize_action.rb +0 -0
  43. data/lib/pdf4me/models/optimize_res.rb +2 -1
  44. data/lib/pdf4me/models/page.rb +0 -0
  45. data/lib/pdf4me/models/page_selection.rb +21 -0
  46. data/lib/pdf4me/models/pdf_a_action.rb +33 -0
  47. data/lib/pdf4me/models/pdf_a_res.rb +8 -0
  48. data/lib/pdf4me/models/pdf_font.rb +9 -0
  49. data/lib/pdf4me/models/rgb_set.rb +10 -0
  50. data/lib/pdf4me/models/rotate.rb +12 -0
  51. data/lib/pdf4me/models/split_action.rb +11 -0
  52. data/lib/pdf4me/models/split_res.rb +8 -0
  53. data/lib/pdf4me/models/stamp_action.rb +60 -0
  54. data/lib/pdf4me/models/stamp_res.rb +8 -0
  55. data/lib/pdf4me/models/text.rb +37 -0
  56. data/lib/pdf4me/models/transform.rb +16 -0
  57. data/lib/pdf4me/models/translate.rb +12 -0
  58. data/lib/pdf4me/utils/assigner.rb +0 -0
  59. data/lib/pdf4me/utils/serializer.rb +2 -0
  60. data/lib/pdf4me/version.rb +1 -1
  61. data/spec/actions/complex_action_spec.rb +12 -0
  62. data/spec/actions/convert_file_to_pdf_spec.rb +21 -0
  63. data/spec/actions/convert_to_pdf_spec.rb +16 -0
  64. data/spec/actions/create_pdf_a_spec.rb +0 -0
  65. data/spec/actions/create_thumbnail_spec.rb +27 -0
  66. data/spec/actions/extract_pages_spec.rb +24 -0
  67. data/spec/actions/extract_spec.rb +16 -0
  68. data/spec/actions/merge_spec.rb +17 -0
  69. data/spec/actions/merge_two_pdfs_spec.rb +21 -0
  70. data/spec/actions/optimize_by_profile_spec.rb +22 -0
  71. data/spec/actions/optimize_spec.rb +16 -0
  72. data/spec/actions/pdf_a_spec.rb +16 -0
  73. data/spec/actions/split_by_page_nr_spec.rb +21 -0
  74. data/spec/actions/split_spec.rb +16 -0
  75. data/spec/actions/stamp_spec.rb +16 -0
  76. data/spec/actions/text_stamp_spec.rb +24 -0
  77. data/spec/actions/wrapper_action_spec.rb +0 -0
  78. data/spec/files/4.pdf +0 -0
  79. data/spec/models/base_spec.rb +9 -0
  80. data/spec/models/color_spec.rb +7 -0
  81. data/spec/models/convert_to_pdf_action_spec.rb +23 -0
  82. data/spec/models/convert_to_pdf_res_spec.rb +7 -0
  83. data/spec/models/create_images_res_spec.rb +7 -0
  84. data/spec/models/custom_cms_config_spec.rb +7 -0
  85. data/spec/models/doc_log_spec.rb +36 -0
  86. data/spec/models/doc_metadata_spec.rb +7 -0
  87. data/spec/models/document_spec.rb +12 -0
  88. data/spec/models/extract_action_spec.rb +7 -0
  89. data/spec/models/extract_res_spec.rb +7 -0
  90. data/spec/models/image_action_spec.rb +46 -0
  91. data/spec/models/merge_action_spec.rb +7 -0
  92. data/spec/models/merge_res_spec.rb +7 -0
  93. data/spec/models/notification_spec.rb +13 -0
  94. data/spec/models/optimize_action_spec.rb +44 -0
  95. data/spec/models/optimize_res_spec.rb +7 -0
  96. data/spec/models/page_selection_spec.rb +17 -0
  97. data/spec/models/page_spec.rb +7 -0
  98. data/spec/models/pdf_a_action_spec.rb +22 -0
  99. data/spec/models/pdf_a_res_spec.rb +7 -0
  100. data/spec/models/pdf_font_spec.rb +7 -0
  101. data/spec/models/rgb_set_spec.rb +7 -0
  102. data/spec/models/rotate_spec.rb +13 -0
  103. data/spec/models/split_action_spec.rb +7 -0
  104. data/spec/models/split_res_spec.rb +7 -0
  105. data/spec/models/stamp_action_spec.rb +27 -0
  106. data/spec/models/stamp_res_spec.rb +7 -0
  107. data/spec/models/text_spec.rb +22 -0
  108. data/spec/models/transform_spec.rb +16 -0
  109. data/spec/models/translate_spec.rb +12 -0
  110. data/spec/spec_helper.rb +0 -0
  111. metadata +142 -90
@@ -0,0 +1,35 @@
1
+ module Pdf4me
2
+ class Merge < ComplexAction
3
+ ATTRIBUTES = %w|documents merge_action|
4
+ attr_accessor *ATTRIBUTES
5
+
6
+ def path
7
+ '/Merge/Merge'
8
+ end
9
+
10
+ def merge_action
11
+ @merge_action || Pdf4me::MergeAction.new
12
+ end
13
+
14
+ # this does not follow the convention at all.
15
+ protected
16
+
17
+ def valid_objects?
18
+ documents.is_a?(Array) &&
19
+ merge_action.is_a?(Pdf4me::MergeAction) &&
20
+ notification.is_a?(Pdf4me::Notification)
21
+ end
22
+
23
+ def valid_instances?
24
+ notification.valid? && merge_action.valid?
25
+ end
26
+
27
+ def serialize_attributes
28
+ {
29
+ documents: documents.map { |document| document.attributes },
30
+ merge_action: merge_action.attributes,
31
+ notification: notification.attributes
32
+ }
33
+ end
34
+ end
35
+ end
@@ -15,10 +15,11 @@ module Pdf4me
15
15
  end
16
16
 
17
17
  def save_path
18
- @save_path ||= File.join(
19
- File.dirname(file1),
20
- "Merged-#{File.basename(file1, ".*")}-#{File.basename(file2, ".*")}.pdf"
21
- )
18
+ @save_path ||= unless file1.nil? && file2.nil?
19
+ File.join(File.dirname(file1),
20
+ "Merged-#{File.basename(file1, ".*")}-#{File.basename(file2, ".*")}.pdf"
21
+ )
22
+ end
22
23
  end
23
24
 
24
25
  def call_api
File without changes
@@ -26,7 +26,9 @@ module Pdf4me
26
26
  end
27
27
 
28
28
  def save_path
29
- @save_path ||= File.join(File.dirname(file), "#{File.basename(file, ".*")}-optimized.pdf")
29
+ @save_path ||= unless file.nil?
30
+ File.join(File.dirname(file), "#{File.basename(file, ".*")}-optimized.pdf")
31
+ end
30
32
  end
31
33
 
32
34
  def call_api
@@ -0,0 +1,10 @@
1
+ module Pdf4me
2
+ class PdfA < ComplexAction
3
+ ATTRIBUTES = %w|document pdf_a_action|
4
+ attr_accessor *ATTRIBUTES
5
+
6
+ def path
7
+ 'PdfA/PdfA'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Pdf4me
2
+ class Split < ComplexAction
3
+ ATTRIBUTES = %w|document split_action|
4
+ attr_accessor *ATTRIBUTES
5
+
6
+ def path
7
+ '/Split/Split'
8
+ end
9
+ end
10
+ end
File without changes
@@ -0,0 +1,10 @@
1
+ module Pdf4me
2
+ class Stamp < ComplexAction
3
+ ATTRIBUTES = %w|document stamp_action|
4
+ attr_accessor *ATTRIBUTES
5
+
6
+ def path
7
+ '/Stamp/Stamp'
8
+ end
9
+ end
10
+ end
@@ -26,8 +26,15 @@ module Pdf4me
26
26
 
27
27
  validate :page_attributes
28
28
 
29
+ def pages=(value)
30
+ @pages = Array(value)
31
+ end
32
+
33
+
29
34
  def save_path
30
- @save_path ||= File.join(File.dirname(file), "#{File.basename(file, ".*")}-stamped.pdf")
35
+ @save_path ||= unless file.nil?
36
+ File.join(File.dirname(file), "#{File.basename(file, ".*")}-stamped.pdf")
37
+ end
31
38
  end
32
39
 
33
40
  def path
@@ -54,7 +61,7 @@ module Pdf4me
54
61
  errors.add(:pages, 'must be valid numeric value')
55
62
  end
56
63
 
57
- unless pages.all? {|i| i.is_a?(Integer) }
64
+ unless pages.all? { |i| i.is_a?(Integer) }
58
65
  errors.add(:pages, 'contains values that are not numbers')
59
66
  end
60
67
  end
File without changes
File without changes
File without changes
File without changes
@@ -17,8 +17,12 @@ module Pdf4me
17
17
  attrs = self.class::ATTRIBUTES.stringify_keys.keys
18
18
  attrs.each_with_object({}) do |attribute, memo|
19
19
  value = send(attribute)
20
+ if value.kind_of?(Pdf4me::Base)
21
+ value = value.attributes
22
+ end
23
+
20
24
  if value.present?
21
- memo[attribute.camelize(:lower)] = send(attribute)
25
+ memo[attribute.camelize(:lower)] = value
22
26
  end
23
27
  end
24
28
  end
@@ -0,0 +1,10 @@
1
+ module Pdf4me
2
+ class Color < Base
3
+ ATTRIBUTES = {
4
+ red: 'Integer',
5
+ green: 'Integer',
6
+ blue: 'Integer'
7
+ }
8
+ attr_accessor *ATTRIBUTES.keys
9
+ end
10
+ end
@@ -1,7 +1,8 @@
1
1
  module Pdf4me
2
2
  class ConvertToPdfRes < Base
3
3
  ATTRIBUTES = {
4
- document: 'Document'
4
+ document: 'Document',
5
+ trace_id: 'String'
5
6
  }
6
7
 
7
8
  attr_accessor *ATTRIBUTES.keys
@@ -0,0 +1,9 @@
1
+ module Pdf4me
2
+ class CreateImagesRes < Base
3
+ ATTRIBUTES = {
4
+ document: 'Document',
5
+ trace_id: 'String'
6
+ }
7
+ attr_accessor *ATTRIBUTES.keys
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Pdf4me
2
+ class CustomCmsConfig < Base
3
+ ATTRIBUTES = {
4
+ white: 'RGBSet',
5
+ c: 'RGBSet',
6
+ m: 'RGBSet',
7
+ y: 'RGBSet',
8
+ k: 'RGBSet',
9
+ cm: 'RGBSet',
10
+ cy: 'RGBSet',
11
+ ck: 'RGBSet',
12
+ my: 'RGBSet',
13
+ mk: 'RGBSet',
14
+ yk: 'RGBSet',
15
+ cmy: 'RGBSet',
16
+ cmk: 'RGBSet',
17
+ cyk: 'RGBSet',
18
+ myk: 'RGBSet',
19
+ cmyk: 'RGBSet'
20
+ }
21
+ attr_accessor *ATTRIBUTES.keys
22
+ end
23
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,28 @@
1
+ module Pdf4me
2
+ class ExtractAction < Base
3
+
4
+ ATTRIBUTES = {
5
+ extract_pages: 'Array<Integer>',
6
+ custom_properties: 'Array<KeyValuePairStringString>'
7
+ }
8
+ attr_accessor *ATTRIBUTES.keys
9
+
10
+ validate :page_attributes
11
+
12
+ def extract_pages=(pages)
13
+ @extract_pages = Array(pages)
14
+ end
15
+
16
+ private
17
+
18
+ def page_attributes
19
+ if extract_pages.empty?
20
+ errors.add(:extract_pages, 'must be valid numeric value')
21
+ end
22
+
23
+ unless extract_pages.all? { |i| i.is_a?(Integer) }
24
+ errors.add(:extract_pages, 'contains values that are not numbers')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module Pdf4me
2
+ class ExtractRes < Base
3
+ ATTRIBUTES = {
4
+ document: 'Document',
5
+ trace_id: 'String'
6
+ }
7
+ attr_accessor *ATTRIBUTES.keys
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Pdf4me
2
+ class Image < Base
3
+ ATTRIBUTES = {
4
+ image_data: 'String',
5
+ image_type: 'String'
6
+ }
7
+ attr_accessor *ATTRIBUTES.keys
8
+
9
+ validates_presence_of :image_data
10
+ end
11
+ end
@@ -0,0 +1,110 @@
1
+ module Pdf4me
2
+ class ImageAction < Base
3
+ ATTRIBUTES = {
4
+ page_selection: 'PageSelection',
5
+ center: 'BOOLEAN',
6
+ fit_page: 'BOOLEAN',
7
+ bits_per_pixel: 'Integer',
8
+ bilevel_threshold: 'Integer',
9
+ width_pixel: 'Integer',
10
+ height_pixel: 'Integer',
11
+ width_point: 'Integer',
12
+ height_point: 'Integer',
13
+ render_options: 'Array<String>',
14
+ rotate_mode: 'String',
15
+ preserve_active_ratio: 'BOOLEAN',
16
+ image_quality: 'Integer',
17
+ cms_engine: 'String',
18
+ custom_cMS_config: 'CustomCmsConfig',
19
+ dithering: 'String',
20
+ dpi: 'Integer',
21
+ fill_order: 'String',
22
+ filter_ratio: 'Integer',
23
+ image_extension: 'String',
24
+ color_space: 'String',
25
+ compression: 'String',
26
+ custom_properties: 'Array<KeyValuePairStringString>'
27
+ }
28
+ attr_accessor *ATTRIBUTES.keys
29
+
30
+ validates_presence_of :image_extension
31
+
32
+ validates_inclusion_of(
33
+ :bits_per_pixel,
34
+ in: [1, 8, 24, 32]
35
+ )
36
+
37
+ validates_inclusion_of(
38
+ :rotate_mode,
39
+ in: %w|none attribute potrait landscape|
40
+ )
41
+
42
+ validates_inclusion_of(
43
+ :cms_engine,
44
+ in: %w|none neugebauer lcms customCMS|
45
+ )
46
+
47
+ validates_inclusion_of(
48
+ :dithering,
49
+ in: %w|none floydSteinberg halftone pattern g3Optimized g4Optimized atkinson|
50
+ )
51
+
52
+ validates_inclusion_of(
53
+ :fill_order,
54
+ in: %w|mSB ISB|
55
+ )
56
+
57
+ validates_inclusion_of(
58
+ :image_extension,
59
+ in: %w|jpg jpeg bmp gif jb2 jp2 jpf jpx png tif tiff|
60
+ )
61
+
62
+ validates_inclusion_of(
63
+ :color_space,
64
+ in: %w|RGB RGBA Gray GrayA CMYK YCbCR YCbCrK Palette LAB CMYK_Konly CMYKA|
65
+ )
66
+
67
+ validates_inclusion_of(
68
+ :compression,
69
+ in: %w|raw jPEG flate LZW group3 group3_2D group4 jBIG2 jPEG2000 tlFFJPEG|
70
+ )
71
+
72
+ validates_numericality_of(
73
+ :bilevel_threshold,
74
+ greater_than_or_equal_to: 0,
75
+ less_than_or_equal_to: 255
76
+ )
77
+
78
+ validates_numericality_of(
79
+ :image_quality,
80
+ greater_than_or_equal_to: 1,
81
+ less_than_or_equal_to: 100
82
+ )
83
+
84
+ validates_numericality_of(
85
+ :filter_ratio,
86
+ greater_than_or_equal_to: 1,
87
+ less_than_or_equal_to: 3
88
+ )
89
+
90
+ def defaults
91
+ {
92
+ center: false,
93
+ fit_page: true,
94
+ bits_per_pixel: 24,
95
+ bilevel_threshold: 181,
96
+ rotate_mode: 'attribute',
97
+ preserve_aspect_ratio: true,
98
+ image_quality: 80,
99
+ cms_engine: 'lcms',
100
+ dithering: 'floydSteinberg',
101
+ dpi: 150,
102
+ fill_order: 'mSB',
103
+ filter_ratio: 1,
104
+ color_space: 'RGB',
105
+ compression: 'LZW',
106
+ }
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,8 @@
1
+ module Pdf4me
2
+ class MergeAction < Base
3
+ ATTRIBUTES = {
4
+ custom_properties: 'Array<KeyValuePairStringString>'
5
+ }
6
+ attr_accessor *ATTRIBUTES.keys
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Pdf4me
2
+ class MergeRes < Base
3
+ ATTRIBUTES = {
4
+ document: 'Document'
5
+ }
6
+ attr_accessor *ATTRIBUTES.keys
7
+ end
8
+ end
@@ -9,7 +9,7 @@ module Pdf4me
9
9
 
10
10
  def defaults
11
11
  {
12
- get_notification: true
12
+ get_notification: false
13
13
  }
14
14
  end
15
15
  end
File without changes
@@ -1,7 +1,8 @@
1
1
  module Pdf4me
2
2
  class OptimizeRes < Base
3
3
  ATTRIBUTES = {
4
- document: 'Document'
4
+ document: 'Document',
5
+ trace_id: 'String'
5
6
  }
6
7
 
7
8
  attr_accessor *ATTRIBUTES.keys
File without changes
@@ -0,0 +1,21 @@
1
+ module Pdf4me
2
+ class PageSelection < Base
3
+ ATTRIBUTES = {
4
+ page_nrs: 'Array<Integer>',
5
+ page_ids: 'Array<String>',
6
+ page_sequence: 'String'
7
+ }
8
+ attr_accessor *ATTRIBUTES.keys
9
+
10
+ validates_inclusion_of(
11
+ :page_sequence,
12
+ in: %w|all first last odd even notFirst notLast|
13
+ )
14
+
15
+ def defaults
16
+ {
17
+ page_sequence: 'all'
18
+ }
19
+ end
20
+ end
21
+ end