pdf4me 1.0.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE → LICENSE.txt} +6 -6
  3. data/README.md +124 -395
  4. data/lib/pdf4me.rb +40 -110
  5. data/lib/pdf4me/actions/complex_action.rb +64 -0
  6. data/lib/pdf4me/actions/convert_file_to_pdf.rb +30 -0
  7. data/lib/pdf4me/actions/convert_to_pdf.rb +14 -0
  8. data/lib/pdf4me/actions/create_pdf_a.rb +29 -0
  9. data/lib/pdf4me/actions/create_thumbnail.rb +55 -0
  10. data/lib/pdf4me/actions/extract_pages.rb +49 -0
  11. data/lib/pdf4me/actions/merge_two_pdfs.rb +34 -0
  12. data/lib/pdf4me/actions/optimize.rb +10 -0
  13. data/lib/pdf4me/actions/optimize_by_profile.rb +42 -0
  14. data/lib/pdf4me/actions/split_by_page_nr.rb +55 -0
  15. data/lib/pdf4me/actions/text_stamp.rb +63 -0
  16. data/lib/pdf4me/actions/wrapper_action.rb +65 -0
  17. data/lib/pdf4me/client.rb +87 -0
  18. data/lib/pdf4me/configuration.rb +9 -88
  19. data/lib/pdf4me/exceptions.rb +26 -0
  20. data/lib/pdf4me/models/base.rb +26 -0
  21. data/lib/pdf4me/models/convert_to_pdf_action.rb +26 -246
  22. data/lib/pdf4me/models/convert_to_pdf_res.rb +5 -185
  23. data/lib/pdf4me/models/doc_log.rb +12 -257
  24. data/lib/pdf4me/models/doc_metadata.rb +13 -282
  25. data/lib/pdf4me/models/document.rb +14 -282
  26. data/lib/pdf4me/models/notification.rb +8 -191
  27. data/lib/pdf4me/models/optimize_action.rb +72 -508
  28. data/lib/pdf4me/models/optimize_res.rb +5 -195
  29. data/lib/pdf4me/models/page.rb +12 -254
  30. data/lib/pdf4me/utils/assigner.rb +10 -0
  31. data/lib/pdf4me/utils/serializer.rb +43 -0
  32. data/lib/pdf4me/version.rb +1 -13
  33. data/spec/actions/create_pdf_a_spec.rb +21 -0
  34. data/spec/actions/wrapper_action_spec.rb +24 -0
  35. data/spec/files/4.pdf +0 -0
  36. data/spec/spec_helper.rb +17 -100
  37. metadata +70 -421
  38. data/Gemfile +0 -7
  39. data/Rakefile +0 -8
  40. data/docs/ActionFlow.md +0 -8
  41. data/docs/ApiUsageRes.md +0 -11
  42. data/docs/ArchiveConfig.md +0 -11
  43. data/docs/ArchiveJobReq.md +0 -12
  44. data/docs/ArchiveJobRes.md +0 -9
  45. data/docs/Color.md +0 -10
  46. data/docs/ConvertApi.md +0 -102
  47. data/docs/ConvertToPdf.md +0 -10
  48. data/docs/ConvertToPdfAction.md +0 -10
  49. data/docs/ConvertToPdfRes.md +0 -8
  50. data/docs/CreateImages.md +0 -10
  51. data/docs/CreateImagesRes.md +0 -8
  52. data/docs/CreatePdfA.md +0 -10
  53. data/docs/CreatePdfARes.md +0 -8
  54. data/docs/CustomCMSConfig.md +0 -23
  55. data/docs/DocAction.md +0 -8
  56. data/docs/DocLog.md +0 -12
  57. data/docs/DocMetadata.md +0 -16
  58. data/docs/Document.md +0 -16
  59. data/docs/DocumentApi.md +0 -203
  60. data/docs/DropDocumentReq.md +0 -20
  61. data/docs/DropDocumentRes.md +0 -15
  62. data/docs/ExecutionTrigger.md +0 -10
  63. data/docs/Extract.md +0 -10
  64. data/docs/ExtractAction.md +0 -9
  65. data/docs/ExtractApi.md +0 -102
  66. data/docs/ExtractRes.md +0 -8
  67. data/docs/GetDocumentListRes.md +0 -13
  68. data/docs/GetDocumentReq.md +0 -14
  69. data/docs/GetDocumentRes.md +0 -14
  70. data/docs/IFormFile.md +0 -13
  71. data/docs/Image.md +0 -15
  72. data/docs/ImageAction.md +0 -30
  73. data/docs/ImageApi.md +0 -107
  74. data/docs/Job.md +0 -10
  75. data/docs/JobApi.md +0 -197
  76. data/docs/JobConfig.md +0 -18
  77. data/docs/JobConfigRes.md +0 -8
  78. data/docs/KeyValuePairStringObject.md +0 -9
  79. data/docs/KeyValuePairStringString.md +0 -9
  80. data/docs/ManagementApi.md +0 -92
  81. data/docs/Merge.md +0 -10
  82. data/docs/MergeAction.md +0 -8
  83. data/docs/MergeApi.md +0 -102
  84. data/docs/MergeRes.md +0 -8
  85. data/docs/Notification.md +0 -9
  86. data/docs/OcrAction.md +0 -12
  87. data/docs/OcrApi.md +0 -57
  88. data/docs/Optimize.md +0 -10
  89. data/docs/OptimizeAction.md +0 -35
  90. data/docs/OptimizeApi.md +0 -103
  91. data/docs/OptimizeRes.md +0 -9
  92. data/docs/Page.md +0 -14
  93. data/docs/PageSelection.md +0 -10
  94. data/docs/Pdf4meAction.md +0 -12
  95. data/docs/Pdf4meDocument.md +0 -32
  96. data/docs/Pdf4meException.md +0 -8
  97. data/docs/PdfAAction.md +0 -14
  98. data/docs/PdfAApi.md +0 -102
  99. data/docs/PdfFont.md +0 -9
  100. data/docs/Pricing.md +0 -13
  101. data/docs/ProduceDocuments.md +0 -14
  102. data/docs/ProduceDocumentsRes.md +0 -8
  103. data/docs/ProduceOutput.md +0 -8
  104. data/docs/RGBSet.md +0 -10
  105. data/docs/RecognizeDocument.md +0 -10
  106. data/docs/RecognizeDocumentRes.md +0 -9
  107. data/docs/Rectangle.md +0 -11
  108. data/docs/Rotate.md +0 -10
  109. data/docs/RunJobRes.md +0 -10
  110. data/docs/SignatureConfig.md +0 -7
  111. data/docs/Split.md +0 -10
  112. data/docs/SplitAction.md +0 -11
  113. data/docs/SplitApi.md +0 -103
  114. data/docs/SplitRes.md +0 -8
  115. data/docs/Stamp.md +0 -10
  116. data/docs/StampAction.md +0 -22
  117. data/docs/StampApi.md +0 -110
  118. data/docs/StampRes.md +0 -8
  119. data/docs/StorageFolder.md +0 -10
  120. data/docs/Text.md +0 -17
  121. data/docs/Transform.md +0 -13
  122. data/docs/Translate.md +0 -9
  123. data/docs/UserFingerprint.md +0 -9
  124. data/docs/VersionRes.md +0 -8
  125. data/docs/java.md +0 -425
  126. data/lib/pdf4me/api/convert_api.rb +0 -130
  127. data/lib/pdf4me/api/document_api.rb +0 -218
  128. data/lib/pdf4me/api/extract_api.rb +0 -131
  129. data/lib/pdf4me/api/image_api.rb +0 -139
  130. data/lib/pdf4me/api/job_api.rb +0 -223
  131. data/lib/pdf4me/api/management_api.rb +0 -117
  132. data/lib/pdf4me/api/merge_api.rb +0 -131
  133. data/lib/pdf4me/api/ocr_api.rb +0 -74
  134. data/lib/pdf4me/api/optimize_api.rb +0 -139
  135. data/lib/pdf4me/api/pdf_a_api.rb +0 -134
  136. data/lib/pdf4me/api/split_api.rb +0 -135
  137. data/lib/pdf4me/api/stamp_api.rb +0 -159
  138. data/lib/pdf4me/api_client.rb +0 -380
  139. data/lib/pdf4me/api_error.rb +0 -38
  140. data/lib/pdf4me/models/action_flow.rb +0 -190
  141. data/lib/pdf4me/models/api_usage_res.rb +0 -219
  142. data/lib/pdf4me/models/archive_config.rb +0 -226
  143. data/lib/pdf4me/models/archive_job_req.rb +0 -249
  144. data/lib/pdf4me/models/archive_job_res.rb +0 -207
  145. data/lib/pdf4me/models/color.rb +0 -206
  146. data/lib/pdf4me/models/convert_to_pdf.rb +0 -209
  147. data/lib/pdf4me/models/create_images.rb +0 -209
  148. data/lib/pdf4me/models/create_images_res.rb +0 -189
  149. data/lib/pdf4me/models/create_pdf_a.rb +0 -209
  150. data/lib/pdf4me/models/create_pdf_a_res.rb +0 -189
  151. data/lib/pdf4me/models/custom_cms_config.rb +0 -323
  152. data/lib/pdf4me/models/doc_action.rb +0 -190
  153. data/lib/pdf4me/models/drop_document_req.rb +0 -348
  154. data/lib/pdf4me/models/drop_document_res.rb +0 -260
  155. data/lib/pdf4me/models/execution_trigger.rb +0 -206
  156. data/lib/pdf4me/models/extract.rb +0 -207
  157. data/lib/pdf4me/models/extract_action.rb +0 -201
  158. data/lib/pdf4me/models/extract_res.rb +0 -188
  159. data/lib/pdf4me/models/get_document_list_res.rb +0 -237
  160. data/lib/pdf4me/models/get_document_req.rb +0 -243
  161. data/lib/pdf4me/models/get_document_res.rb +0 -246
  162. data/lib/pdf4me/models/i_form_file.rb +0 -235
  163. data/lib/pdf4me/models/image.rb +0 -300
  164. data/lib/pdf4me/models/image_action.rb +0 -513
  165. data/lib/pdf4me/models/job.rb +0 -213
  166. data/lib/pdf4me/models/job_config.rb +0 -298
  167. data/lib/pdf4me/models/job_config_res.rb +0 -193
  168. data/lib/pdf4me/models/key_value_pair_string_object.rb +0 -197
  169. data/lib/pdf4me/models/key_value_pair_string_string.rb +0 -197
  170. data/lib/pdf4me/models/merge.rb +0 -209
  171. data/lib/pdf4me/models/merge_action.rb +0 -190
  172. data/lib/pdf4me/models/merge_res.rb +0 -188
  173. data/lib/pdf4me/models/ocr_action.rb +0 -259
  174. data/lib/pdf4me/models/optimize.rb +0 -209
  175. data/lib/pdf4me/models/page_selection.rb +0 -246
  176. data/lib/pdf4me/models/pdf4me_action.rb +0 -259
  177. data/lib/pdf4me/models/pdf4me_document.rb +0 -511
  178. data/lib/pdf4me/models/pdf4me_exception.rb +0 -189
  179. data/lib/pdf4me/models/pdf_a_action.rb +0 -297
  180. data/lib/pdf4me/models/pdf_font.rb +0 -213
  181. data/lib/pdf4me/models/pricing.rb +0 -278
  182. data/lib/pdf4me/models/produce_documents.rb +0 -251
  183. data/lib/pdf4me/models/produce_documents_res.rb +0 -191
  184. data/lib/pdf4me/models/produce_output.rb +0 -221
  185. data/lib/pdf4me/models/recognize_document.rb +0 -209
  186. data/lib/pdf4me/models/recognize_document_res.rb +0 -198
  187. data/lib/pdf4me/models/rectangle.rb +0 -215
  188. data/lib/pdf4me/models/rgb_set.rb +0 -206
  189. data/lib/pdf4me/models/rotate.rb +0 -221
  190. data/lib/pdf4me/models/run_job_res.rb +0 -215
  191. data/lib/pdf4me/models/signature_config.rb +0 -179
  192. data/lib/pdf4me/models/split.rb +0 -207
  193. data/lib/pdf4me/models/split_action.rb +0 -219
  194. data/lib/pdf4me/models/split_res.rb +0 -190
  195. data/lib/pdf4me/models/stamp.rb +0 -209
  196. data/lib/pdf4me/models/stamp_action.rb +0 -387
  197. data/lib/pdf4me/models/stamp_res.rb +0 -189
  198. data/lib/pdf4me/models/storage_folder.rb +0 -239
  199. data/lib/pdf4me/models/text.rb +0 -320
  200. data/lib/pdf4me/models/transform.rb +0 -263
  201. data/lib/pdf4me/models/translate.rb +0 -207
  202. data/lib/pdf4me/models/user_fingerprint.rb +0 -197
  203. data/lib/pdf4me/models/version_res.rb +0 -188
  204. data/pdf4me.gemspec +0 -47
  205. data/spec/api/convert_api_spec.rb +0 -60
  206. data/spec/api/document_api_spec.rb +0 -83
  207. data/spec/api/extract_api_spec.rb +0 -60
  208. data/spec/api/image_api_spec.rb +0 -62
  209. data/spec/api/job_api_spec.rb +0 -82
  210. data/spec/api/management_api_spec.rb +0 -57
  211. data/spec/api/merge_api_spec.rb +0 -60
  212. data/spec/api/ocr_api_spec.rb +0 -47
  213. data/spec/api/optimize_api_spec.rb +0 -60
  214. data/spec/api/pdf_a_api_spec.rb +0 -60
  215. data/spec/api/split_api_spec.rb +0 -60
  216. data/spec/api/stamp_api_spec.rb +0 -63
  217. data/spec/api_client_spec.rb +0 -226
  218. data/spec/configuration_spec.rb +0 -42
  219. data/spec/models/action_flow_spec.rb +0 -42
  220. data/spec/models/api_usage_res_spec.rb +0 -60
  221. data/spec/models/archive_config_spec.rb +0 -60
  222. data/spec/models/archive_job_req_spec.rb +0 -66
  223. data/spec/models/archive_job_res_spec.rb +0 -48
  224. data/spec/models/color_spec.rb +0 -54
  225. data/spec/models/convert_to_pdf_action_spec.rb +0 -62
  226. data/spec/models/convert_to_pdf_res_spec.rb +0 -42
  227. data/spec/models/convert_to_pdf_spec.rb +0 -54
  228. data/spec/models/create_images_res_spec.rb +0 -42
  229. data/spec/models/create_images_spec.rb +0 -54
  230. data/spec/models/create_pdf_a_res_spec.rb +0 -42
  231. data/spec/models/create_pdf_a_spec.rb +0 -54
  232. data/spec/models/custom_cms_config_spec.rb +0 -132
  233. data/spec/models/doc_action_spec.rb +0 -42
  234. data/spec/models/doc_log_spec.rb +0 -70
  235. data/spec/models/doc_metadata_spec.rb +0 -90
  236. data/spec/models/document_spec.rb +0 -90
  237. data/spec/models/drop_document_req_spec.rb +0 -118
  238. data/spec/models/drop_document_res_spec.rb +0 -84
  239. data/spec/models/execution_trigger_spec.rb +0 -54
  240. data/spec/models/extract_action_spec.rb +0 -48
  241. data/spec/models/extract_res_spec.rb +0 -42
  242. data/spec/models/extract_spec.rb +0 -54
  243. data/spec/models/get_document_list_res_spec.rb +0 -72
  244. data/spec/models/get_document_req_spec.rb +0 -78
  245. data/spec/models/get_document_res_spec.rb +0 -78
  246. data/spec/models/i_form_file_spec.rb +0 -72
  247. data/spec/models/image_action_spec.rb +0 -206
  248. data/spec/models/image_spec.rb +0 -88
  249. data/spec/models/job_config_res_spec.rb +0 -42
  250. data/spec/models/job_config_spec.rb +0 -102
  251. data/spec/models/job_spec.rb +0 -54
  252. data/spec/models/key_value_pair_string_object_spec.rb +0 -48
  253. data/spec/models/key_value_pair_string_string_spec.rb +0 -48
  254. data/spec/models/merge_action_spec.rb +0 -42
  255. data/spec/models/merge_res_spec.rb +0 -42
  256. data/spec/models/merge_spec.rb +0 -54
  257. data/spec/models/notification_spec.rb +0 -48
  258. data/spec/models/ocr_action_spec.rb +0 -70
  259. data/spec/models/optimize_action_spec.rb +0 -228
  260. data/spec/models/optimize_res_spec.rb +0 -48
  261. data/spec/models/optimize_spec.rb +0 -54
  262. data/spec/models/page_selection_spec.rb +0 -58
  263. data/spec/models/page_spec.rb +0 -78
  264. data/spec/models/pdf4me_action_spec.rb +0 -70
  265. data/spec/models/pdf4me_document_spec.rb +0 -202
  266. data/spec/models/pdf4me_exception_spec.rb +0 -42
  267. data/spec/models/pdf_a_action_spec.rb +0 -86
  268. data/spec/models/pdf_font_spec.rb +0 -48
  269. data/spec/models/pricing_spec.rb +0 -80
  270. data/spec/models/produce_documents_res_spec.rb +0 -42
  271. data/spec/models/produce_documents_spec.rb +0 -78
  272. data/spec/models/produce_output_spec.rb +0 -46
  273. data/spec/models/recognize_document_res_spec.rb +0 -48
  274. data/spec/models/recognize_document_spec.rb +0 -54
  275. data/spec/models/rectangle_spec.rb +0 -60
  276. data/spec/models/rgb_set_spec.rb +0 -54
  277. data/spec/models/rotate_spec.rb +0 -54
  278. data/spec/models/run_job_res_spec.rb +0 -54
  279. data/spec/models/signature_config_spec.rb +0 -36
  280. data/spec/models/split_action_spec.rb +0 -60
  281. data/spec/models/split_res_spec.rb +0 -42
  282. data/spec/models/split_spec.rb +0 -54
  283. data/spec/models/stamp_action_spec.rb +0 -142
  284. data/spec/models/stamp_res_spec.rb +0 -42
  285. data/spec/models/stamp_spec.rb +0 -54
  286. data/spec/models/storage_folder_spec.rb +0 -58
  287. data/spec/models/text_spec.rb +0 -104
  288. data/spec/models/transform_spec.rb +0 -72
  289. data/spec/models/translate_spec.rb +0 -48
  290. data/spec/models/user_fingerprint_spec.rb +0 -48
  291. data/spec/models/version_res_spec.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 431d852c1c429c6d2f4197af206dca26c866cbfd
4
- data.tar.gz: 522eb046ccbece19c09f9f768734f26842df365d
3
+ metadata.gz: f4bac55f297137229d59ff76c455941c0c6038c5
4
+ data.tar.gz: b8e5adbb69464bcc0817b21bf41024e9d7a19562
5
5
  SHA512:
6
- metadata.gz: f7ecb848b188c207e5f55efcaafd3e9a215a5da2e4eb5363db3778e082b2fc6248a6b59a4a28af3a3d8f115e452209f2628a4f6412d1378a7ce1b1bfee724000
7
- data.tar.gz: d8bd4e8e19c5c44b4375f827a4dfcf46de25deff2137742bbf0330d5035704ad6d2e17e9bc15a1f85cdc71ddc4c708e956b68fc0c464772a42eb4341b2c64954
6
+ metadata.gz: f9d9e79554f8d23e335487d53b6040f0e06e3c702b9908c5a54a5d56efdbd6aab24cfcc1e40d99a4bb0df34897587d24447133b503cf970d0addda8a85810845
7
+ data.tar.gz: 8122fdc82c118e791eac26786866a3986450c6ac96b9046c49a14a9db56207793ee46b84e9050892217c17948345a17fd13296ea786e62bef287f8891384341a
@@ -1,6 +1,6 @@
1
- MIT License
1
+ The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 pdf4me
3
+ Copyright (c) 2018 arpanlepcha
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -4,39 +4,23 @@
4
4
  The tool provides utility over common PDF related task like `merge`, `create`, `stamp` and others, which can be
5
5
  found below.
6
6
 
7
- ## Getting Started
7
+ ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- ```shell
12
- gem 'pdf4me'
13
- ```
14
-
15
- And then execute
16
- ```shell
17
- bundle install
18
- # OR If you don't use bundler
19
- gem install pdf4me
11
+ ```ruby
12
+ gem 'pdf4me'
20
13
  ```
21
14
 
22
- ## Build locally/for development
23
- To build the Ruby code into a gem:
15
+ And then execute:
24
16
 
25
- ```shell
26
- gem build pdf4me.gemspec
27
- ```
28
-
29
- Then either install the gem locally:
17
+ $ bundle
30
18
 
31
- ```shell
32
- gem install ./pdf4me-1.0.0.gem
33
- ```
19
+ Or install it yourself as:
34
20
 
35
- ## Install from Git
21
+ $ gem install pdf4me
36
22
 
37
- You can also install from a git repository: https://github.com/pdf4me/pdf4me-clientapi-ruby.git, then add the following in the Gemfile:
38
-
39
- gem 'pdf4me', :git => 'https://github.com/pdf4me/pdf4me-clientapi-ruby.git'
23
+ ## Usage
40
24
 
41
25
  ## Initializing Pdf4me
42
26
  Pdf4me works with any Rack application or plain old ruby script. In any regular script the configuration of Pdf4me looks like
@@ -50,436 +34,181 @@ Pdf4me works with any Rack application or plain old ruby script. In any regular
50
34
  require 'pdf4me'
51
35
 
52
36
  Pdf4me.configure do |config|
53
- config.host = 'api-dev.pdf4me.com'
54
- config.debugging = true
55
- config.app_id = 'your-app-id'
56
- config.app_secret = 'your-app-secret'
37
+ config.host = 'api-dev.pdf4me.com'
38
+ config.token = 'valid-token'
57
39
  end
58
40
  ```
59
-
60
41
  ## Basic Usage
42
+ > All basic methods exposes a safe and a dangerous method to execute the operation.
43
+ > If the run fails, you can get the error through `.errors`
61
44
 
62
45
  ### convert_file_to_pdf
63
- > Given a file, convert the file to PDF
46
+ > Given a file, convert the file to PDF. if `save_path` is not provided, the converted PDF is by defauled saved as file_name provided.
64
47
 
65
48
  ```ruby
66
- api_instance = Pdf4me::ConvertApi.new
67
- file = File.open(file_path, 'rb')
68
- response = api_instance.convert_file_to_pdf(
69
- file_name: 'some-name',
70
- file: file
71
- )
72
- file.close
73
- ```
74
-
75
-
76
- ### convert_to_pdf
77
- > Given a file, convert the file to PDF, with finer controls as opposed to
78
- `convert_file_to_pdf`. The request is instantiated as a hash with the `:req` key,
79
- that takes in `Pdf4me::ConvertToPdf` model.
80
-
81
- > The model itself is comprised of three more models, `:document`, `:convertToPdfAction`
82
- and `:notification`
83
-
84
- ```ruby
85
- api_instance = Pdf4me::ConvertApi.new
86
- opts = {
87
- req: Pdf4me::ConvertToPdf.new(
88
- document: Pdf4me::Document.new(
89
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
90
- ),
91
- convertToPdfAction: Pdf4me::ConvertToPdfAction.new(
92
- options: ""
93
- ),
94
- notification: Pdf4me::Notification.new(
95
- getNotification: true
96
- )
97
- )
98
- }
99
- result = api_instance.convert_to_pdf(opts)
100
- ```
49
+ b = Pdf4me::ConvertFileToPdf.new(
50
+ file: '/path/to/file/3.pdf',
51
+ save_path: 'converted.pdf'
52
+ )
53
+ b.run! # dangerous method
54
+ b.run # safe method - returns true|false
101
55
 
102
- ### extract
103
- > Extract out pages from PDF. You can choose from the pages you want to extract
56
+ b.errors # to show errors
104
57
 
105
- ```ruby
106
- api_instance = Pdf4me::ExtractApi.new
107
-
108
- opts = {
109
- req: Pdf4me::Extract.new(
110
- document: Pdf4me::Document.new(
111
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
112
- ),
113
- extractAction: Pdf4me::ExtractAction.new(
114
- extractPages: Array.wrap(pages)
115
- ),
116
- notification: Pdf4me::Notification.new(
117
- getNotification: true
118
- )
119
- )
120
- }
121
- api_instance.extract(opts)
122
58
  ```
123
59
 
124
-
125
60
  ### extract_pages
126
- > Utility function on top of extract, that trades complexity for configuration.
61
+ > Extract particular set of pages from given PDF
127
62
 
128
63
  ```ruby
129
- api_instance = Pdf4me::ExtractApi.new
130
- response = File.open(file_path, 'rb') do |file|
131
- api_instance.extract_pages(
132
- page_nrs: '2,3,4',
133
- file: file
134
- )
135
- end
136
-
137
- # OR
138
- file = File.open(file_path, 'rb')
139
- response = api_instance.extract_pages(
140
- page_nrs: '2,3',
141
- file: file
64
+ a = Pdf4me::ExtractPages.new(
65
+ file: '/path/to/file/3.pdf',
66
+ pages: [4],
67
+ save_path: 'extracted.pdf'
142
68
  )
143
- file.close
144
-
145
- # do something with response a tempfile
146
- FileUtils.cp(response.path, '/new/file/path.pdf')
147
- ```
148
-
149
- ### create_images
150
- > Creates images from the PDF Document. This is useful if you want to create thumbnails for the PDF
151
- > The options are highly configurable to get the desired output.
152
- > The output would be a base64 encoded object that you have to save.
153
-
154
- ```ruby
155
- # initialize the API client
156
- api_instance = Pdf4me::ImageApi.new
157
-
158
- # make request hash
159
- opts = {
160
- req: Pdf4me::CreateImages.new(
161
- document: Pdf4me::Document.new(
162
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
163
- ),
164
- imageAction: Pdf4me::ImageAction.new(
165
- pageSelection: Pdf4me::PageSelection.new(
166
- pageNrs: [1,2,3]
167
- ),
168
- imageExtension: 'png',
169
- center: true,
170
- fitPage: true,
171
- bitsPerPixel: 24,
172
- bilevelThreshold: 181,
173
- renderOptions: %w(noAntialiasing),
174
- rotateMode: 'none',
175
- preserveAspectRatio: true,
176
- compression: 'raw'
177
- ),
178
- notification: Pdf4me::Notification.new(
179
- getNotification: true
180
- )
181
- )
182
- }
183
-
184
- # response and save
185
- response = api_instance.create_images(opts)
186
- File.open(save_path, 'wb') do |f|
187
- f.write(Base64.decode64(response.document.doc_data))
188
- end
69
+ a.run
189
70
  ```
190
71
 
191
72
  ### create_thumbnail
192
- > This is again a wrapper method on top of `:create_images`. The configuration is little less heckling
73
+ > Create Thumbnail from existing PDF for a particular page number.
74
+ > This takes in some additional configuration `width` defaulting to 100px, `image_format` defaulting to PNG
193
75
 
194
76
  ```ruby
195
- api_instance = Pdf4me::ImageApi.new
196
- file = File.open(file_path, 'rb')
197
-
198
- response = api_instance.create_thumbnail(
199
- 100, # width in pixels
200
- page_nr: "1", # for which page
201
- image_format: "png", # image format
202
- file: file
77
+ a = Pdf4me::CreateThumbnail.new(
78
+ file: '/path/to/file/3.pdf',
79
+ page_number: 4,
80
+ width: 120,
81
+ save_path: 'thumbnail.png'
203
82
  )
204
-
205
- file.close
206
-
207
- # do something with response a tempfile
208
- FileUtils.cp(response.path, '/new/file/path.png')
209
- ````
210
-
211
- ### merge
212
- > Merges two or more PDF and gives MergeRes, a Base64 Encoded file
213
-
214
- ```ruby
215
- # Initialize the API client
216
- api_instance = Pdf4me::MergeApi.new
217
-
218
- # make request Hash
219
- opts = {
220
- req: Pdf4me::Merge.new(
221
- documents: [
222
- Pdf4me::Document.new(
223
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
224
- ),
225
- Pdf4me::Document.new(
226
- docData: Base64.encode64(File.open(file_path_2, 'rb', &:read)),
227
- ),
228
- ],
229
- mergeAction: Pdf4me::MergeAction.new,
230
- notification: Pdf4me::Notification.new
231
- )
232
- }
233
-
234
- # make request
235
- response = api_instance.merge(opts)
236
- File.open(save_path, 'wb') do |f|
237
- f.write(Base64.decode64(response.document.doc_data))
238
- end
239
- ````
83
+ a.run
84
+ ```
240
85
 
241
86
  ### merge2_pdfs
242
- > Utility method that merges two pdfs
87
+ > Merges two PDFs, the order of merge is defined by the arguments passed.
88
+ > * `file1` would always be the first followed by `file2` in merged PDF
243
89
 
244
90
  ```ruby
245
- api_instance = Pdf4me::MergeApi.new
246
-
247
- file1 = File.open(file_path, 'rb')
248
- file2 = File.open(file_path_2, 'rb')
249
-
250
- response = api_instance.merge2_pdfs(
251
- file1: file1,
252
- file2: file2
91
+ a = Pdf4me::MergeTwoPdfs.new(
92
+ file1: '/path/to/file/3.pdf',
93
+ file2: '/path/to/file/4.pdf',
94
+ save_path: 'merged.pdf'
253
95
  )
96
+ a.run
97
+ ```
254
98
 
255
- file1.close
256
- file2.close
99
+ ###optimize_by_profile
100
+ > Optimizes a PDF based on th the profile argument passed.
101
+ > * valid values for profile are `default`, `web`, `print`, `max`, `mRC`
257
102
 
258
- # do something with response a tempfile
259
- FileUtils.cp(response.path, '/new/file/path.pdf')
103
+ ```ruby
104
+ a = Pdf4me::OptimizeByProfile.new(
105
+ file: '/path/to/file/3.pdf',
106
+ profile: 'max',
107
+ save_path: 'optimized.pdf'
108
+ )
109
+ a.run
260
110
  ```
261
111
 
262
- ###optimize
263
112
 
264
- > Given a PDF document, Optimize the document.
265
- > `:optimize` takes multiple arguments, the arguments are
266
- >
267
- > * profile, valid values are `default`, `web`, `print`, `max`, `mRC`
268
- > * dithering_mode, valid values are `none`, `floydSteinberg`, `halftone`, `pattern`, `g3Optimized`, `g4Optimized`, `atkinson`
269
-
270
- For complete list of options, please refer the `OptimizeAction` class
113
+ ### create_pdf_a
114
+ > Creates a PDF/A Compliant document from a given PDF. By default it does not return any response.
115
+ > * valid values for compliances are `unknown`, `pdf10`, `pdf11`, `pdf12`, `pdf13`, `pdf14`, `pdfA1b`, `pdfA1a`, `pdf15`, `pdf16`, `pdf17`, `pdfA2b`, `pdfA2u`, `pdfA2a`, `pdfA3b`, `pdfA3u`, `pdfA3a`
271
116
 
272
117
  ```ruby
273
- # Initialize the API client
274
- api_instance = Pdf4me::OptimizeApi.new
275
-
276
- # prepare Request Hash
277
- opts = {
278
- req: Pdf4me::Optimize.new(
279
- document: Pdf4me::Document.new(
280
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
281
- ),
282
- optimizeAction: Pdf4me::OptimizeAction.new(
283
- profile: profile,
284
- useProfile: true,
285
- optimizeResources: true,
286
- ditheringMode: dithering_mode
287
- ),
288
- notification: Pdf4me::Notification.new(
289
- getNotification: true
290
- )
291
- )
292
- }
293
-
294
- # make request
295
- response = api_instance.optimize(opts)
296
- File.open(save_path, 'wb') do |f|
297
- f.write(Base64.decode64(response.document.doc_data))
298
- end
299
-
118
+ a = Pdf4me::CreatePdfA.new(
119
+ file: '/path/to/file/4.pdf',
120
+ compliance: 'pdfA1a',
121
+ save_path: 'to_pdfa.pdf'
122
+ )
123
+ a.run
300
124
  ```
301
125
 
302
- ###optimize_by_profile
303
- > Utility function, that optimizes the PDF based on Profile as mentioned above
126
+ ### split_by_page_nr
127
+ > Split a given PDF into two with page number as the pivot point.
304
128
 
305
129
  ```ruby
306
- api_instance = Pdf4me::OptimizeApi.new
307
- file = File.open(file_path, 'rb')
308
-
309
- response = api_instance.optimize_by_profile(
310
- 'print',
311
- file: file
312
- )
313
- file.close
314
-
315
- # do something with response a tempfile
316
- FileUtils.cp(response.path, '/new/file/path.pdf')
130
+ a = Pdf4me::SplitByPageNr.new(
131
+ file: '/path/to/file/3.pdf',
132
+ page_number: 3,
133
+ first_pdf: 'first.pdf', # defaults to '/path/to/file/3-first.pdf'
134
+ second_pdf: 'second.pdf' # defaults to '/path/to/file/3-second.pdf'
135
+ )
136
+ a.run
317
137
  ```
318
138
 
319
- ### pdf_a
320
- > Creates PDF/A Documents. There are range of options that could be passed while creating the document. The options are
321
- > - `compliance` _string_ - Anyone of the following values `unknown`, `pdf10`, `pdf11`, `pdf12`, `pdf13`, `pdf14`, `pdfA1b`, `pdfA1a`, `pdf15`, `pdf16`, `pdf17`, `pdfA2b`, `pdfA2u`, `pdfA2a`, `pdfA3b`, `pdfA3u`, `pdfA3a`
322
- > - `downgrade` _boolean_ `true` or `false`
323
- > - `upgrade` _boolean_ `true` or `false`
324
- > - `linearize` _boolean_ `true` or `false`
139
+ ### text_stamp
140
+ > Stamp a PDF with a text on particular sets of pages
141
+ > Stamp takes additional arguments
142
+ > * `position_x` - Position at X-Axis, valid values are `left`, `center`, `right`
143
+ > * `position_y` - Position at Y-Axis, valid values are `top`, `middle`, `bottom`
144
+ > * text - Text to stamp the PDF with and its mandatory.
325
145
 
326
146
  ```ruby
327
- api_instance = Pdf4me::PdfAApi.new
328
-
329
- opts = {
330
- req: Pdf4me::CreatePdfA.new(
331
- document: Pdf4me::Document.new(
332
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
333
- ),
334
- pdfAAction: Pdf4me::PdfAAction.new(
335
- compliance: 'pdfA1a',
336
- allowDowngrade: true,
337
- allowUpgrade: true,
338
- outputIntentProfile: 'sRGBColorSpace',
339
- linearize: true
340
- ),
341
- notification: Pdf4me::Notification.new(
342
- getNotification: true
343
- )
344
- )
345
- }
346
-
347
- # make request
348
- response = api_instance.pdf_a(opts)
349
- File.open('/path/to/save.pdf', 'wb') do |f|
350
- f.write(Base64.decode64(response.document.doc_data))
351
- end
147
+ a = Pdf4me::TextStamp.new(
148
+ file: '/path/to/file/3.pdf',
149
+ pages: [1, 3],
150
+ position_x: 'left',
151
+ position_y: 'top',
152
+ text: 'Hell Pdf4me',
153
+ save_path: 'stamped.pdf'
154
+ )
155
+ a.run
352
156
  ```
353
157
 
354
- ### create_pdf_a
355
- > Utility function based on above function
356
158
 
357
- ```ruby
358
- api_instance = Pdf4me::PdfAApi.new
359
- file = File.open(file_path, 'rb')
159
+ ## Advanced Usage
160
+ > These methods are more complex than the Basic Wrapper methods. The development of which is still a Work in Progress. Currently there are two methods that you can use
360
161
 
361
- response = api_instance.create_pdf_a(
362
- pdf_compliance: 'pdfA1a',
363
- file: file
364
- )
162
+ ###convert_to_pdf
365
163
 
366
- file.close
367
-
368
- # do something with response a tempfile
369
- FileUtils.cp(response.path, '/new/file/path.pdf')
370
- ```
164
+ > Given a file, convert the file to PDF, with finer controls as opposed to
165
+ `convert_file_to_pdf`. The request is instantiated as a hash with the `:req` key,
166
+ that takes in `Pdf4me::ConvertToPdf` model.
371
167
 
372
- ### split
373
- > Given a PDF, split the PDF into two parts
168
+ > The action takes three different models `:document`, `:convertToPdfAction` and `:notification` and returns
169
+ `Pdf4me::ConvertToPdfRes`
374
170
 
375
171
  ```ruby
376
- api_instance = Pdf4me::SplitApi.new
377
-
378
- opts = {
379
- req: Pdf4me::Split.new(
380
- document: Pdf4me::Document.new(
381
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
382
- ),
383
- SplitAction: Pdf4me::SplitAction.new(
384
- splitAfterPage: 3
385
- ),
386
- notificaiton: Pdf4me::Notification.new(
387
- getNotification: true
388
- )
389
- )
390
- }
391
-
392
- response = api_instance.split(opts)
393
-
394
- File.open(save_path, 'wb') do |f|
395
- f.write(Base64.decode64(response.documents[0].doc_data))
396
- end
172
+ file_path = '/path/to/file/TestDocToConvert.docx'
397
173
 
398
- File.open(save_path_2, 'wb') do |f|
399
- f.write(Base64.decode64(response.documents[0].doc_data))
400
- end
174
+ d = Pdf4me::ConvertToPdf.new(
175
+ document: Pdf4me::Document.new(
176
+ doc_data: Base64.encode64(File.open(file_path, 'rb', &:read)),
177
+ name: "TestDocToConvert.docx"
178
+ ),
179
+ convert_to_pdf_action: Pdf4me::ConvertToPdfAction.new
180
+ )
181
+ response = d.run
401
182
  ```
402
183
 
184
+ ###optimize
403
185
 
404
- ### split_by_page_nr
405
- > Utility function to split the PDF by page number
186
+ > Given a PDF document, Optimize the document and return `Pdf4me::OptimizeRes`
187
+ >
188
+ > `:optimize` takes three different models `document`, `optimize_action` and `notification`
189
+ >
190
+ > `Pdf4me::OptimizeAction` takes multiple arguments, but most importantly `profile` is important
191
+ > * profile, valid values are `default`, `web`, `print`, `max`, `mRC`
406
192
 
407
193
  ```ruby
408
- api_instance = Pdf4me::SplitApi.new
409
- file = File.open(file_path, 'rb')
410
-
411
- response = api_instance.split_by_page_nr(
412
- 2, # page_number
413
- file: file
414
- )
194
+ file = '/path/to/file/4.pdf'
415
195
 
416
- file.close
417
-
418
- File.open(save_path, 'wb') do |f|
419
- f.write(Base64.decode64(response.documents[0].doc_data))
420
- end
421
-
422
- File.open(save_path_2, 'wb') do |f|
423
- f.write(Base64.decode64(response.documents[0].doc_data))
424
- end
196
+ Pdf4me::Optimize.new(
197
+ document: Pdf4me::Document.new(
198
+ doc_data: Base64.encode64(File.open(fi, 'rb', &:read))
199
+ ),
200
+ optimize_action: Pdf4me::OptimizeAction.new(
201
+ use_profile: true,
202
+ profile: 'max'
203
+ )
204
+ )
425
205
  ```
426
206
 
427
- # stamp
428
- > Stamp a PDF, based on Stamp Action.
429
- > You can stamp either a text or image to PDF, There are two separate methods defined to help you with stamping
430
- > - Stamp PDF with image
431
- > - Stamp PDF with Text
432
- > Depending upon the type of stamp, position, size can be configured.
207
+ ## Contributing
433
208
 
434
- ```ruby
435
- api_instance = Pdf4me::StampApi.new
436
-
437
- opts = {
438
- req: Pdf4me::Stamp.new(
439
- document: Pdf4me::Document.new(
440
- docData: Base64.encode64(File.open(file_path, 'rb', &:read)),
441
- ),
442
- stampAction: Pdf4me::StampAction.new(
443
- image: Pdf4me::Image.new(
444
- imageData: Base64.encode64(File.open(image, 'rb', &:read)),
445
- ),
446
- sizeX: stamp_width,
447
- sizeY: stamp_length,
448
- rotate: rotate,
449
- alignX: align_x,
450
- alignY: align_y,
451
- scale: 'relToA4',
452
- stampType: 'foreground',
453
- alpha: opacity
454
- ),
455
- notification: Pdf4me::Notification.new(
456
- getNotification: true
457
- )
458
- )
459
- }
460
-
461
- response = api_instance.stamp(opts)
462
- File.open(save_path_2, 'wb') do |f|
463
- f.write(Base64.decode64(response.document.doc_data))
464
- end
465
- ```
209
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pdf4me/pdf4me-clientapi-ruby.
466
210
 
467
- ### text_stamp
468
- > Utility function over stamp, where you can stamp a document with text
211
+ ## License
469
212
 
470
- ```ruby
471
- api_instance = Pdf4me::StampApi.new
472
- file = File.open(file_path, 'rb')
473
-
474
- response = api_instance.text_stamp(
475
- 'right', # alignment x axis
476
- 'bottom', # alignment y axis,
477
- text: 'Hello world, i am stamp',
478
- pages: '1,4',
479
- file: file
480
- )
481
- file.close
213
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
482
214
 
483
- # do something with response a tempfile
484
- FileUtils.cp(response.path, '/new/file/path.pdf')
485
- ```