pdf4me 1.0.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE → LICENSE.txt} +6 -6
- data/README.md +124 -395
- data/lib/pdf4me.rb +40 -110
- data/lib/pdf4me/actions/complex_action.rb +64 -0
- data/lib/pdf4me/actions/convert_file_to_pdf.rb +30 -0
- data/lib/pdf4me/actions/convert_to_pdf.rb +14 -0
- data/lib/pdf4me/actions/create_pdf_a.rb +29 -0
- data/lib/pdf4me/actions/create_thumbnail.rb +55 -0
- data/lib/pdf4me/actions/extract_pages.rb +49 -0
- data/lib/pdf4me/actions/merge_two_pdfs.rb +34 -0
- data/lib/pdf4me/actions/optimize.rb +10 -0
- data/lib/pdf4me/actions/optimize_by_profile.rb +42 -0
- data/lib/pdf4me/actions/split_by_page_nr.rb +55 -0
- data/lib/pdf4me/actions/text_stamp.rb +63 -0
- data/lib/pdf4me/actions/wrapper_action.rb +65 -0
- data/lib/pdf4me/client.rb +87 -0
- data/lib/pdf4me/configuration.rb +9 -88
- data/lib/pdf4me/exceptions.rb +26 -0
- data/lib/pdf4me/models/base.rb +26 -0
- data/lib/pdf4me/models/convert_to_pdf_action.rb +26 -246
- data/lib/pdf4me/models/convert_to_pdf_res.rb +5 -185
- data/lib/pdf4me/models/doc_log.rb +12 -257
- data/lib/pdf4me/models/doc_metadata.rb +13 -282
- data/lib/pdf4me/models/document.rb +14 -282
- data/lib/pdf4me/models/notification.rb +8 -191
- data/lib/pdf4me/models/optimize_action.rb +72 -508
- data/lib/pdf4me/models/optimize_res.rb +5 -195
- data/lib/pdf4me/models/page.rb +12 -254
- data/lib/pdf4me/utils/assigner.rb +10 -0
- data/lib/pdf4me/utils/serializer.rb +43 -0
- data/lib/pdf4me/version.rb +1 -13
- data/spec/actions/create_pdf_a_spec.rb +21 -0
- data/spec/actions/wrapper_action_spec.rb +24 -0
- data/spec/files/4.pdf +0 -0
- data/spec/spec_helper.rb +17 -100
- metadata +70 -421
- data/Gemfile +0 -7
- data/Rakefile +0 -8
- data/docs/ActionFlow.md +0 -8
- data/docs/ApiUsageRes.md +0 -11
- data/docs/ArchiveConfig.md +0 -11
- data/docs/ArchiveJobReq.md +0 -12
- data/docs/ArchiveJobRes.md +0 -9
- data/docs/Color.md +0 -10
- data/docs/ConvertApi.md +0 -102
- data/docs/ConvertToPdf.md +0 -10
- data/docs/ConvertToPdfAction.md +0 -10
- data/docs/ConvertToPdfRes.md +0 -8
- data/docs/CreateImages.md +0 -10
- data/docs/CreateImagesRes.md +0 -8
- data/docs/CreatePdfA.md +0 -10
- data/docs/CreatePdfARes.md +0 -8
- data/docs/CustomCMSConfig.md +0 -23
- data/docs/DocAction.md +0 -8
- data/docs/DocLog.md +0 -12
- data/docs/DocMetadata.md +0 -16
- data/docs/Document.md +0 -16
- data/docs/DocumentApi.md +0 -203
- data/docs/DropDocumentReq.md +0 -20
- data/docs/DropDocumentRes.md +0 -15
- data/docs/ExecutionTrigger.md +0 -10
- data/docs/Extract.md +0 -10
- data/docs/ExtractAction.md +0 -9
- data/docs/ExtractApi.md +0 -102
- data/docs/ExtractRes.md +0 -8
- data/docs/GetDocumentListRes.md +0 -13
- data/docs/GetDocumentReq.md +0 -14
- data/docs/GetDocumentRes.md +0 -14
- data/docs/IFormFile.md +0 -13
- data/docs/Image.md +0 -15
- data/docs/ImageAction.md +0 -30
- data/docs/ImageApi.md +0 -107
- data/docs/Job.md +0 -10
- data/docs/JobApi.md +0 -197
- data/docs/JobConfig.md +0 -18
- data/docs/JobConfigRes.md +0 -8
- data/docs/KeyValuePairStringObject.md +0 -9
- data/docs/KeyValuePairStringString.md +0 -9
- data/docs/ManagementApi.md +0 -92
- data/docs/Merge.md +0 -10
- data/docs/MergeAction.md +0 -8
- data/docs/MergeApi.md +0 -102
- data/docs/MergeRes.md +0 -8
- data/docs/Notification.md +0 -9
- data/docs/OcrAction.md +0 -12
- data/docs/OcrApi.md +0 -57
- data/docs/Optimize.md +0 -10
- data/docs/OptimizeAction.md +0 -35
- data/docs/OptimizeApi.md +0 -103
- data/docs/OptimizeRes.md +0 -9
- data/docs/Page.md +0 -14
- data/docs/PageSelection.md +0 -10
- data/docs/Pdf4meAction.md +0 -12
- data/docs/Pdf4meDocument.md +0 -32
- data/docs/Pdf4meException.md +0 -8
- data/docs/PdfAAction.md +0 -14
- data/docs/PdfAApi.md +0 -102
- data/docs/PdfFont.md +0 -9
- data/docs/Pricing.md +0 -13
- data/docs/ProduceDocuments.md +0 -14
- data/docs/ProduceDocumentsRes.md +0 -8
- data/docs/ProduceOutput.md +0 -8
- data/docs/RGBSet.md +0 -10
- data/docs/RecognizeDocument.md +0 -10
- data/docs/RecognizeDocumentRes.md +0 -9
- data/docs/Rectangle.md +0 -11
- data/docs/Rotate.md +0 -10
- data/docs/RunJobRes.md +0 -10
- data/docs/SignatureConfig.md +0 -7
- data/docs/Split.md +0 -10
- data/docs/SplitAction.md +0 -11
- data/docs/SplitApi.md +0 -103
- data/docs/SplitRes.md +0 -8
- data/docs/Stamp.md +0 -10
- data/docs/StampAction.md +0 -22
- data/docs/StampApi.md +0 -110
- data/docs/StampRes.md +0 -8
- data/docs/StorageFolder.md +0 -10
- data/docs/Text.md +0 -17
- data/docs/Transform.md +0 -13
- data/docs/Translate.md +0 -9
- data/docs/UserFingerprint.md +0 -9
- data/docs/VersionRes.md +0 -8
- data/docs/java.md +0 -425
- data/lib/pdf4me/api/convert_api.rb +0 -130
- data/lib/pdf4me/api/document_api.rb +0 -218
- data/lib/pdf4me/api/extract_api.rb +0 -131
- data/lib/pdf4me/api/image_api.rb +0 -139
- data/lib/pdf4me/api/job_api.rb +0 -223
- data/lib/pdf4me/api/management_api.rb +0 -117
- data/lib/pdf4me/api/merge_api.rb +0 -131
- data/lib/pdf4me/api/ocr_api.rb +0 -74
- data/lib/pdf4me/api/optimize_api.rb +0 -139
- data/lib/pdf4me/api/pdf_a_api.rb +0 -134
- data/lib/pdf4me/api/split_api.rb +0 -135
- data/lib/pdf4me/api/stamp_api.rb +0 -159
- data/lib/pdf4me/api_client.rb +0 -380
- data/lib/pdf4me/api_error.rb +0 -38
- data/lib/pdf4me/models/action_flow.rb +0 -190
- data/lib/pdf4me/models/api_usage_res.rb +0 -219
- data/lib/pdf4me/models/archive_config.rb +0 -226
- data/lib/pdf4me/models/archive_job_req.rb +0 -249
- data/lib/pdf4me/models/archive_job_res.rb +0 -207
- data/lib/pdf4me/models/color.rb +0 -206
- data/lib/pdf4me/models/convert_to_pdf.rb +0 -209
- data/lib/pdf4me/models/create_images.rb +0 -209
- data/lib/pdf4me/models/create_images_res.rb +0 -189
- data/lib/pdf4me/models/create_pdf_a.rb +0 -209
- data/lib/pdf4me/models/create_pdf_a_res.rb +0 -189
- data/lib/pdf4me/models/custom_cms_config.rb +0 -323
- data/lib/pdf4me/models/doc_action.rb +0 -190
- data/lib/pdf4me/models/drop_document_req.rb +0 -348
- data/lib/pdf4me/models/drop_document_res.rb +0 -260
- data/lib/pdf4me/models/execution_trigger.rb +0 -206
- data/lib/pdf4me/models/extract.rb +0 -207
- data/lib/pdf4me/models/extract_action.rb +0 -201
- data/lib/pdf4me/models/extract_res.rb +0 -188
- data/lib/pdf4me/models/get_document_list_res.rb +0 -237
- data/lib/pdf4me/models/get_document_req.rb +0 -243
- data/lib/pdf4me/models/get_document_res.rb +0 -246
- data/lib/pdf4me/models/i_form_file.rb +0 -235
- data/lib/pdf4me/models/image.rb +0 -300
- data/lib/pdf4me/models/image_action.rb +0 -513
- data/lib/pdf4me/models/job.rb +0 -213
- data/lib/pdf4me/models/job_config.rb +0 -298
- data/lib/pdf4me/models/job_config_res.rb +0 -193
- data/lib/pdf4me/models/key_value_pair_string_object.rb +0 -197
- data/lib/pdf4me/models/key_value_pair_string_string.rb +0 -197
- data/lib/pdf4me/models/merge.rb +0 -209
- data/lib/pdf4me/models/merge_action.rb +0 -190
- data/lib/pdf4me/models/merge_res.rb +0 -188
- data/lib/pdf4me/models/ocr_action.rb +0 -259
- data/lib/pdf4me/models/optimize.rb +0 -209
- data/lib/pdf4me/models/page_selection.rb +0 -246
- data/lib/pdf4me/models/pdf4me_action.rb +0 -259
- data/lib/pdf4me/models/pdf4me_document.rb +0 -511
- data/lib/pdf4me/models/pdf4me_exception.rb +0 -189
- data/lib/pdf4me/models/pdf_a_action.rb +0 -297
- data/lib/pdf4me/models/pdf_font.rb +0 -213
- data/lib/pdf4me/models/pricing.rb +0 -278
- data/lib/pdf4me/models/produce_documents.rb +0 -251
- data/lib/pdf4me/models/produce_documents_res.rb +0 -191
- data/lib/pdf4me/models/produce_output.rb +0 -221
- data/lib/pdf4me/models/recognize_document.rb +0 -209
- data/lib/pdf4me/models/recognize_document_res.rb +0 -198
- data/lib/pdf4me/models/rectangle.rb +0 -215
- data/lib/pdf4me/models/rgb_set.rb +0 -206
- data/lib/pdf4me/models/rotate.rb +0 -221
- data/lib/pdf4me/models/run_job_res.rb +0 -215
- data/lib/pdf4me/models/signature_config.rb +0 -179
- data/lib/pdf4me/models/split.rb +0 -207
- data/lib/pdf4me/models/split_action.rb +0 -219
- data/lib/pdf4me/models/split_res.rb +0 -190
- data/lib/pdf4me/models/stamp.rb +0 -209
- data/lib/pdf4me/models/stamp_action.rb +0 -387
- data/lib/pdf4me/models/stamp_res.rb +0 -189
- data/lib/pdf4me/models/storage_folder.rb +0 -239
- data/lib/pdf4me/models/text.rb +0 -320
- data/lib/pdf4me/models/transform.rb +0 -263
- data/lib/pdf4me/models/translate.rb +0 -207
- data/lib/pdf4me/models/user_fingerprint.rb +0 -197
- data/lib/pdf4me/models/version_res.rb +0 -188
- data/pdf4me.gemspec +0 -47
- data/spec/api/convert_api_spec.rb +0 -60
- data/spec/api/document_api_spec.rb +0 -83
- data/spec/api/extract_api_spec.rb +0 -60
- data/spec/api/image_api_spec.rb +0 -62
- data/spec/api/job_api_spec.rb +0 -82
- data/spec/api/management_api_spec.rb +0 -57
- data/spec/api/merge_api_spec.rb +0 -60
- data/spec/api/ocr_api_spec.rb +0 -47
- data/spec/api/optimize_api_spec.rb +0 -60
- data/spec/api/pdf_a_api_spec.rb +0 -60
- data/spec/api/split_api_spec.rb +0 -60
- data/spec/api/stamp_api_spec.rb +0 -63
- data/spec/api_client_spec.rb +0 -226
- data/spec/configuration_spec.rb +0 -42
- data/spec/models/action_flow_spec.rb +0 -42
- data/spec/models/api_usage_res_spec.rb +0 -60
- data/spec/models/archive_config_spec.rb +0 -60
- data/spec/models/archive_job_req_spec.rb +0 -66
- data/spec/models/archive_job_res_spec.rb +0 -48
- data/spec/models/color_spec.rb +0 -54
- data/spec/models/convert_to_pdf_action_spec.rb +0 -62
- data/spec/models/convert_to_pdf_res_spec.rb +0 -42
- data/spec/models/convert_to_pdf_spec.rb +0 -54
- data/spec/models/create_images_res_spec.rb +0 -42
- data/spec/models/create_images_spec.rb +0 -54
- data/spec/models/create_pdf_a_res_spec.rb +0 -42
- data/spec/models/create_pdf_a_spec.rb +0 -54
- data/spec/models/custom_cms_config_spec.rb +0 -132
- data/spec/models/doc_action_spec.rb +0 -42
- data/spec/models/doc_log_spec.rb +0 -70
- data/spec/models/doc_metadata_spec.rb +0 -90
- data/spec/models/document_spec.rb +0 -90
- data/spec/models/drop_document_req_spec.rb +0 -118
- data/spec/models/drop_document_res_spec.rb +0 -84
- data/spec/models/execution_trigger_spec.rb +0 -54
- data/spec/models/extract_action_spec.rb +0 -48
- data/spec/models/extract_res_spec.rb +0 -42
- data/spec/models/extract_spec.rb +0 -54
- data/spec/models/get_document_list_res_spec.rb +0 -72
- data/spec/models/get_document_req_spec.rb +0 -78
- data/spec/models/get_document_res_spec.rb +0 -78
- data/spec/models/i_form_file_spec.rb +0 -72
- data/spec/models/image_action_spec.rb +0 -206
- data/spec/models/image_spec.rb +0 -88
- data/spec/models/job_config_res_spec.rb +0 -42
- data/spec/models/job_config_spec.rb +0 -102
- data/spec/models/job_spec.rb +0 -54
- data/spec/models/key_value_pair_string_object_spec.rb +0 -48
- data/spec/models/key_value_pair_string_string_spec.rb +0 -48
- data/spec/models/merge_action_spec.rb +0 -42
- data/spec/models/merge_res_spec.rb +0 -42
- data/spec/models/merge_spec.rb +0 -54
- data/spec/models/notification_spec.rb +0 -48
- data/spec/models/ocr_action_spec.rb +0 -70
- data/spec/models/optimize_action_spec.rb +0 -228
- data/spec/models/optimize_res_spec.rb +0 -48
- data/spec/models/optimize_spec.rb +0 -54
- data/spec/models/page_selection_spec.rb +0 -58
- data/spec/models/page_spec.rb +0 -78
- data/spec/models/pdf4me_action_spec.rb +0 -70
- data/spec/models/pdf4me_document_spec.rb +0 -202
- data/spec/models/pdf4me_exception_spec.rb +0 -42
- data/spec/models/pdf_a_action_spec.rb +0 -86
- data/spec/models/pdf_font_spec.rb +0 -48
- data/spec/models/pricing_spec.rb +0 -80
- data/spec/models/produce_documents_res_spec.rb +0 -42
- data/spec/models/produce_documents_spec.rb +0 -78
- data/spec/models/produce_output_spec.rb +0 -46
- data/spec/models/recognize_document_res_spec.rb +0 -48
- data/spec/models/recognize_document_spec.rb +0 -54
- data/spec/models/rectangle_spec.rb +0 -60
- data/spec/models/rgb_set_spec.rb +0 -54
- data/spec/models/rotate_spec.rb +0 -54
- data/spec/models/run_job_res_spec.rb +0 -54
- data/spec/models/signature_config_spec.rb +0 -36
- data/spec/models/split_action_spec.rb +0 -60
- data/spec/models/split_res_spec.rb +0 -42
- data/spec/models/split_spec.rb +0 -54
- data/spec/models/stamp_action_spec.rb +0 -142
- data/spec/models/stamp_res_spec.rb +0 -42
- data/spec/models/stamp_spec.rb +0 -54
- data/spec/models/storage_folder_spec.rb +0 -58
- data/spec/models/text_spec.rb +0 -104
- data/spec/models/transform_spec.rb +0 -72
- data/spec/models/translate_spec.rb +0 -48
- data/spec/models/user_fingerprint_spec.rb +0 -48
- data/spec/models/version_res_spec.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4bac55f297137229d59ff76c455941c0c6038c5
|
4
|
+
data.tar.gz: b8e5adbb69464bcc0817b21bf41024e9d7a19562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9d9e79554f8d23e335487d53b6040f0e06e3c702b9908c5a54a5d56efdbd6aab24cfcc1e40d99a4bb0df34897587d24447133b503cf970d0addda8a85810845
|
7
|
+
data.tar.gz: 8122fdc82c118e791eac26786866a3986450c6ac96b9046c49a14a9db56207793ee46b84e9050892217c17948345a17fd13296ea786e62bef287f8891384341a
|
data/{LICENSE → LICENSE.txt}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
MIT License
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2018
|
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
|
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
|
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
|
-
##
|
7
|
+
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
```
|
12
|
-
|
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
|
-
|
23
|
-
To build the Ruby code into a gem:
|
15
|
+
And then execute:
|
24
16
|
|
25
|
-
|
26
|
-
gem build pdf4me.gemspec
|
27
|
-
```
|
28
|
-
|
29
|
-
Then either install the gem locally:
|
17
|
+
$ bundle
|
30
18
|
|
31
|
-
|
32
|
-
gem install ./pdf4me-1.0.0.gem
|
33
|
-
```
|
19
|
+
Or install it yourself as:
|
34
20
|
|
35
|
-
|
21
|
+
$ gem install pdf4me
|
36
22
|
|
37
|
-
|
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
|
-
|
54
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
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
|
-
>
|
61
|
+
> Extract particular set of pages from given PDF
|
127
62
|
|
128
63
|
```ruby
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
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
|
-
>
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
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
|
-
>
|
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
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
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
|
-
|
256
|
-
|
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
|
-
|
259
|
-
|
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
|
-
|
265
|
-
>
|
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
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
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
|
-
###
|
303
|
-
>
|
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
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
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
|
-
###
|
320
|
-
>
|
321
|
-
>
|
322
|
-
>
|
323
|
-
>
|
324
|
-
>
|
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
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
358
|
-
|
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
|
-
|
362
|
-
pdf_compliance: 'pdfA1a',
|
363
|
-
file: file
|
364
|
-
)
|
162
|
+
###convert_to_pdf
|
365
163
|
|
366
|
-
|
367
|
-
|
368
|
-
|
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
|
-
|
373
|
-
|
168
|
+
> The action takes three different models `:document`, `:convertToPdfAction` and `:notification` and returns
|
169
|
+
`Pdf4me::ConvertToPdfRes`
|
374
170
|
|
375
171
|
```ruby
|
376
|
-
|
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
|
-
|
399
|
-
|
400
|
-
|
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
|
-
|
405
|
-
>
|
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
|
-
|
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
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
468
|
-
> Utility function over stamp, where you can stamp a document with text
|
211
|
+
## License
|
469
212
|
|
470
|
-
|
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
|
-
```
|