ilovepdf 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +12 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +21 -0
  8. data/README.md +142 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +17 -0
  11. data/bin/setup +8 -0
  12. data/ilovepdf.gemspec +35 -0
  13. data/lib/ilovepdf.rb +36 -0
  14. data/lib/ilovepdf/errors.rb +51 -0
  15. data/lib/ilovepdf/file.rb +36 -0
  16. data/lib/ilovepdf/ilovepdf.rb +142 -0
  17. data/lib/ilovepdf/response.rb +36 -0
  18. data/lib/ilovepdf/task.rb +195 -0
  19. data/lib/ilovepdf/tool/compress.rb +20 -0
  20. data/lib/ilovepdf/tool/imagepdf.rb +27 -0
  21. data/lib/ilovepdf/tool/merge.rb +13 -0
  22. data/lib/ilovepdf/tool/officepdf.rb +13 -0
  23. data/lib/ilovepdf/tool/pagenumber.rb +40 -0
  24. data/lib/ilovepdf/tool/pdfa.rb +26 -0
  25. data/lib/ilovepdf/tool/pdfjpg.rb +22 -0
  26. data/lib/ilovepdf/tool/protect.rb +13 -0
  27. data/lib/ilovepdf/tool/repair.rb +12 -0
  28. data/lib/ilovepdf/tool/rotate.rb +12 -0
  29. data/lib/ilovepdf/tool/split.rb +35 -0
  30. data/lib/ilovepdf/tool/unlock.rb +12 -0
  31. data/lib/ilovepdf/tool/watermark.rb +49 -0
  32. data/lib/ilovepdf/version.rb +3 -0
  33. data/samples/compress_advanced.rb +25 -0
  34. data/samples/compress_basic.rb +14 -0
  35. data/samples/merge_advanced.rb +22 -0
  36. data/samples/merge_basic.rb +18 -0
  37. data/samples/pdfa_advanced.rb +21 -0
  38. data/samples/pdfa_basic.rb +17 -0
  39. data/samples/repair_advanced.rb +21 -0
  40. data/samples/repair_basic.rb +17 -0
  41. data/samples/rotate_advanced.rb +21 -0
  42. data/samples/rotate_basic.rb +17 -0
  43. data/samples/split_advanced.rb +32 -0
  44. data/samples/split_advanced_merge.rb +30 -0
  45. data/samples/split_basic.rb +17 -0
  46. data/samples/try_catch_errors.rb +46 -0
  47. data/samples/unlock_advanced.rb +21 -0
  48. data/samples/unlock_basic.rb +17 -0
  49. data/samples/watermark_advanced.rb +57 -0
  50. data/samples/watermark_basic.rb +20 -0
  51. data/uploads/sample_pdf.pdf +0 -0
  52. metadata +209 -0
@@ -0,0 +1,12 @@
1
+ module Ilovepdf
2
+ module Tool
3
+ class Unlock < ::Ilovepdf::Task
4
+ API_PARAMS = []
5
+
6
+ def initialize(public_key, secret_key)
7
+ self.tool = :unlock
8
+ super(public_key, secret_key)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,49 @@
1
+ module Ilovepdf
2
+ module Tool
3
+ class Watermark < ::Ilovepdf::Task
4
+ API_PARAMS = [
5
+ :mode, :text, :image, :pages, :vertical_position, :horizontal_position,
6
+ :vertical_position_adjustment, :horizontal_position_adjustment, :mosaic,
7
+ :rotate, :font_family, :font_style, :font_size, :font_color, :transparency,
8
+ :layer
9
+ ]
10
+
11
+ attr_accessor *API_PARAMS
12
+
13
+ VERTICAL_POSITION_VALUES = ['bottom', 'center' ,'top']
14
+ HORIZONTAL_POSITION_VALUES = ['left', 'middle', 'right']
15
+ FONT_FAMILY_VALUES = ['Arial', 'Arial Unicode MS', 'Verdana', 'Courier',
16
+ 'Times New Roman', 'Comic Sans MS', 'WenQuanYi Zen Hei',
17
+ 'Lohit Marathi'
18
+ ]
19
+
20
+ LAYER_VALUES = ['above', 'below']
21
+
22
+ def initialize(public_key, secret_key)
23
+ self.tool = :watermark
24
+ super(public_key, secret_key)
25
+ end
26
+
27
+ def vertical_position=(new_val)
28
+ raise Errors::ArgumentEnumError.new(VERTICAL_POSITION_VALUES) unless VERTICAL_POSITION_VALUES.include? new_val
29
+ @vertical_position = new_val
30
+ end
31
+
32
+ def horizontal_position=(new_val)
33
+ raise Errors::ArgumentEnumError.new(HORIZONTAL_POSITION_VALUES) unless HORIZONTAL_POSITION_VALUES.include? new_val
34
+ @horizontal_position = new_val
35
+ end
36
+
37
+ def font_family=(new_val)
38
+ raise Errors::ArgumentEnumError.new(FONT_FAMILY_VALUES) unless FONT_FAMILY_VALUES.include? new_val
39
+ @font_family = new_val
40
+ end
41
+
42
+ def layer=(new_val)
43
+ raise Errors::ArgumentEnumError.new(LAYER_VALUES) unless LAYER_VALUES.include? new_val
44
+ @layer = new_val
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Ilovepdf
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Compress.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # We can rotate a file
11
+ file.rotate = 90
12
+
13
+ # Set compression level
14
+ my_task.compression_level = 'extreme'
15
+
16
+ # and set name for output file.
17
+ # the task will set the correct file extension for you
18
+ my_task.output_filename = 'lowlow_compression'
19
+
20
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
21
+ response = my_task.execute
22
+ puts "Time spent doing processing the task: #{response.body['timer']}" # You can check the time spent processing the task
23
+
24
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
25
+ my_task.download 'path/to/download'
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Compress.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # Process files
11
+ response = my_task.execute
12
+
13
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
14
+ my_task.download
@@ -0,0 +1,22 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # Start the manager class
5
+ ilovepdf = Ilovepdf::Ilovepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # and get the task tool
8
+ my_task = ilovepdf.new_task :merge
9
+
10
+ # File object keeps information about its server_filename and the properties you can set
11
+ fileA = my_task.add_file '/path/to/file/document_a.pdf'
12
+ fileB = my_task.add_file '/path/to/file/document_b.pdf'
13
+
14
+ # and set name for output file.
15
+ # the task will set the correct file extension for you.
16
+ my_task.output_filename = 'merged_filename'
17
+
18
+ # Process files
19
+ response = my_task.execute
20
+
21
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
22
+ my_task.download 'path/to/download'
@@ -0,0 +1,18 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # Start the manager class
5
+ ilovepdf = Ilovepdf::Ilovepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # and get the task tool
8
+ my_task = ilovepdf.new_task :merge
9
+
10
+ # File object keeps information about its server_filename and the properties you can set
11
+ fileA = my_task.add_file '/path/to/file/document_a.pdf'
12
+ fileB = my_task.add_file '/path/to/file/document_b.pdf'
13
+
14
+ # Process files
15
+ response = my_task.execute
16
+
17
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
18
+ my_task.download 'path/to/download'
@@ -0,0 +1,21 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Pdfa.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # Set conformance
11
+ file.conformance = 'pdfa-1b'
12
+
13
+ # and set name for output file.
14
+ # the task will set the correct file extension for you.
15
+ my_task.output_filename = 'merged_filename'
16
+
17
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
18
+ my_task.execute
19
+
20
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
21
+ my_task.download('path/to/download')
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Pdfa.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # Set conformance
11
+ file.conformance = 'pdfa-1b'
12
+
13
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
14
+ response = my_task.execute
15
+
16
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
17
+ my_task.download('path/to/download')
@@ -0,0 +1,21 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # Start the manager class
5
+ ilovepdf = Ilovepdf::Ilovepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # and get the task tool
8
+ my_task = ilovepdf.new_task :repair
9
+
10
+ # File object keeps information about its server_filename and the properties you can set
11
+ file = my_task.add_file '/path/to/file/document_a.pdf'
12
+
13
+ # and set name for output file.
14
+ # the task will set the correct file extension for you.
15
+ my_task.output_filename = 'repaired_filename'
16
+
17
+ # Process files
18
+ response = my_task.execute
19
+
20
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
21
+ my_task.download 'path/to/download'
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # Start the manager class
5
+ ilovepdf = Ilovepdf::Ilovepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # and get the task tool
8
+ my_task = ilovepdf.new_task :repair
9
+
10
+ # File object keeps information about its server_filename and the properties you can set
11
+ file = my_task.add_file '/path/to/file/document_a.pdf'
12
+
13
+ # Process files
14
+ response = my_task.execute
15
+
16
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
17
+ my_task.download 'path/to/download'
@@ -0,0 +1,21 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Rotate.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # We can rotate a file
11
+ file.rotate = 90;
12
+
13
+ # and set name for output file.
14
+ # the task will set the correct file extension for you
15
+ my_task.output_filename = 'rotated_file'
16
+
17
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
18
+ response = my_task.execute
19
+
20
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
21
+ my_task.download('path/to/download')
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Rotate.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # We can rotate a file
11
+ file.rotate = 90;
12
+
13
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
14
+ response = my_task.execute
15
+
16
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
17
+ my_task.download('path/to/download')
@@ -0,0 +1,32 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # Start the manager class
5
+ ilovepdf = Ilovepdf::Ilovepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # and get the task tool
8
+ my_task = ilovepdf.new_task :split
9
+
10
+ # or you can call task class directly, this set the same tool as before
11
+ my_task = Ilovepdf::Tool::Split.new("PUBLIC_KEY", "SECRET_KEY");
12
+
13
+
14
+ # File object keeps information about its server_filename and the properties you can set
15
+ file = my_task.add_file '/path/to/file/document.pdf'
16
+
17
+ # set ranges to split the document
18
+ my_task.ranges = "2-4,6-8"
19
+
20
+ # and set name for output file.
21
+ # the task will set the correct file extension for you
22
+ my_task.packaged_filename = 'split_documents'
23
+
24
+ # and name for splitted document (inside the zip file)
25
+ my_task.output_filename = 'split'
26
+
27
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
28
+ response = my_task.execute
29
+ puts "Time spent doing processing the task: #{response.body['timer']}" # You can check the time spent processing the task
30
+
31
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
32
+ my_task.download 'path/to/download'
@@ -0,0 +1,30 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # Start the manager class
5
+ ilovepdf = Ilovepdf::Ilovepdf.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # and get the task tool
8
+ my_task = ilovepdf.new_task :split
9
+
10
+ # or you can call task class directly, this set the same tool as before
11
+ my_task = Ilovepdf::Tool::Split.new("PUBLIC_KEY", "SECRET_KEY");
12
+
13
+
14
+ # File object keeps information about its server_filename and the properties you can set
15
+ file = my_task.add_file '/path/to/file/document.pdf'
16
+
17
+ # Set ranges to split the document
18
+ my_task.ranges = "2-4,6-8"
19
+
20
+ # We want the splitted files to be merged into a single one
21
+ my_task.merge_after = true
22
+
23
+ # and name for merged document
24
+ my_task.output_filename = 'split'
25
+
26
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
27
+ my_task.execute
28
+
29
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
30
+ my_task.download 'path/to/download'
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # or you can call task class directly, this set the same tool as before
5
+ my_task = Ilovepdf::Tool::Split.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # set ranges to split the document
11
+ my_task.ranges = "2-4,6-8"
12
+
13
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
14
+ response = my_task.execute
15
+
16
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
17
+ my_task.download 'path/to/download'
@@ -0,0 +1,46 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ begin
5
+ # Get an instance of the task tool Split
6
+ my_task = Ilovepdf::Tool::Split.new("PUBLIC_KEY", "SECRET_KEY");
7
+
8
+ # File object keeps information about its server_filename and the properties you can set
9
+ #file = my_task.add_file '/path/to/file/document.pdf'
10
+ file = my_task.add_file ::Ilovepdf.root.join("uploads/sample_pdf.pdf")
11
+ # set ranges to split the document
12
+ my_task.ranges = '2-4,6-8'
13
+
14
+ # and set name for output file.
15
+ # the task will set the correct file extension for you
16
+ my_task.packaged_filename = 'split_documents'
17
+
18
+ # and name for splitted document (inside the zip file)
19
+ my_task.output_filename = 'split'
20
+ my_task.execute
21
+ my_task.download
22
+ rescue Ilovepdf::Errors::AuthError => e # Catch Auth errors
23
+ puts "An error occurred on Auth: " + e.message
24
+ # To examine more in depth what the server returned:
25
+ # puts e.http_response.body
26
+ rescue Ilovepdf::Errors::StartError => e # Catch API errors from Start endpoint
27
+ puts "An error occurred on Start: " + e.message
28
+ # To examine more in depth what the server returned:
29
+ # puts e.http_response.body
30
+ rescue Ilovepdf::Errors::UploadError => e # Catch API errors from Upload endpoint
31
+ puts "An error occurred on Upload: " + e.message
32
+ # To examine more in depth what the server returned:
33
+ # puts e.http_response.body
34
+ rescue Ilovepdf::Errors::ProcessError => e # Catch API errors from Process endpoint
35
+ puts "An error occurred on Process: " + e.message
36
+ # To examine more in depth what the server returned:
37
+ # puts e.http_response.body
38
+ rescue Ilovepdf::ApiError => e
39
+ puts "An error occurred on an API call to Ilovepdf: " + e.message
40
+ # To examine more in depth what the server returned:
41
+ # puts e.http_response.body
42
+ rescue Ilovepdf::Error => e # Catch library errors
43
+ puts "An error occurred on the lib: " + e.message
44
+ rescue StandardError => e # Catch all errors
45
+ puts "Something went wrong: #{e.message}"
46
+ end
@@ -0,0 +1,21 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Unlock.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # set the current password of the locked PDF you want to unlock
11
+ file.password = 'test'
12
+
13
+ # and set name for output file.
14
+ # the task will set the correct file extension for you
15
+ my_task.output_filename = 'unlocked'
16
+
17
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
18
+ my_task.execute
19
+
20
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
21
+ my_task.download 'path/to/download'
@@ -0,0 +1,17 @@
1
+ require "bundler/setup"
2
+ require 'ilovepdf'
3
+
4
+ # You can call task class directly
5
+ my_task = Ilovepdf::Tool::Unlock.new("PUBLIC_KEY", "SECRET_KEY");
6
+
7
+ # File object keeps information about its server_filename and the properties you can set
8
+ file = my_task.add_file '/path/to/file/document.pdf'
9
+
10
+ # set the current password of the locked PDF you want to unlock
11
+ file.password = 'test'
12
+
13
+ # Finally is time to process the files. i.e We'll send them to Ilovepdf servers :)
14
+ my_task.execute
15
+
16
+ # and finally download the file. If no path is set, it will be downloaded on your current working directory
17
+ my_task.download 'path/to/download'