pdfserve_client 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +110 -0
- data/lib/pdfserve_client/client.rb +40 -0
- data/lib/pdfserve_client/merge.rb +45 -0
- data/lib/pdfserve_client/split.rb +54 -0
- data/lib/pdfserve_client/stamp.rb +52 -0
- data/lib/pdfserve_client/version.rb +5 -0
- data/lib/pdfserve_client.rb +3 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 55f08ddb2b267ba05ac6c1fcb49c2506cab4b762811eb4edd1fea0e421b3459f
|
4
|
+
data.tar.gz: 998567a407fecc32c6f30c594049c9be7f3dbb3d88fcecc15c5b7096195d0aec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 831380373c2db34056b9a2b7021cc871fc3a9779a6fbe76b2bb6c82ecf5c1c3a6a3801611bcfa97433e40dcad6c9760e550493b5ce3b94e00ffc3fd0897d3348
|
7
|
+
data.tar.gz: 44da7b08a931dd2c721b2fa9b0320f3a44a641117c70435a505966dfa797e94c768f863ed24219ea8bfb1548442d91d1ac8b3dd642e4413eb55e658d110916e8
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# PdfserveClient
|
2
|
+
|
3
|
+
PdfserveClient is a gem to merge, stamp or split PDF files using the service https://github.com/ant31/pdfserve.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pdfserve_client', '~> 2.0'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### PDFServe Client
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'pdfserve_client'
|
25
|
+
|
26
|
+
file_urls = [
|
27
|
+
'https://s3-public.de/file1.pdf',
|
28
|
+
'https://s3-public.de/file2.pdf'
|
29
|
+
]
|
30
|
+
output_path = './output.pdf'
|
31
|
+
|
32
|
+
client = PdfserveClient::Client.new(api_endpoint: 'https://your.custom.endpoint')
|
33
|
+
client.merge(file_urls:, output_path:)
|
34
|
+
```
|
35
|
+
|
36
|
+
or with a token
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
|
40
|
+
require 'pdfserve_client'
|
41
|
+
|
42
|
+
file_urls = [
|
43
|
+
'https://s3-public.de/file1.pdf',
|
44
|
+
'https://s3-public.de/file2.pdf'
|
45
|
+
]
|
46
|
+
output_path = './output.pdf'
|
47
|
+
|
48
|
+
client = PdfserveClient::Client.new(api_endpoint: 'https://your.custom.endpoint', api_token: 'the-token')
|
49
|
+
client.merge(file_urls:, output_path:)
|
50
|
+
```
|
51
|
+
|
52
|
+
`file_urls` needs to be an array of urls (images or pdfs) that need to be merged and in the order how you want to merge it
|
53
|
+
`output_path` it can be a tmp file in the machine that makes the call
|
54
|
+
|
55
|
+
|
56
|
+
### PDF Stamp
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'pdfserve_client'
|
60
|
+
|
61
|
+
file_url = 'https://s3-public.de/file1.pdf'
|
62
|
+
stamp_text = 'A1'
|
63
|
+
|
64
|
+
client = PdfserveClient::Client.new(api_endpoint: 'https://your.custom.endpoint')
|
65
|
+
client.stamp(file_url:, stamp_text:)
|
66
|
+
```
|
67
|
+
|
68
|
+
or with a token
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
|
72
|
+
require 'pdfserve_client'
|
73
|
+
|
74
|
+
file_url = 'https://s3-public.de/file1.pdf'
|
75
|
+
stamp_text = 'A1'
|
76
|
+
|
77
|
+
client = PdfserveClient::Client.new(api_endpoint: 'https://your.custom.endpoint', api_token: 'the-token')
|
78
|
+
client.stamp(file_url:, stamp_text:)
|
79
|
+
```
|
80
|
+
|
81
|
+
`file_url` needs to be the url (image or pdf) that need to be stamped
|
82
|
+
`stamp_text` it needs to be the text you want to add at the top right of the file
|
83
|
+
|
84
|
+
### PDF Split
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
require 'pdfserve_client'
|
88
|
+
|
89
|
+
file_url = 'https://s3-public.de/file1.pdf'
|
90
|
+
pages = '1-3,4,6-8'
|
91
|
+
|
92
|
+
client = PdfserveClient::Client.new(api_endpoint: 'https://your.custom.endpoint')
|
93
|
+
client.split(file_url:, pages:)
|
94
|
+
```
|
95
|
+
|
96
|
+
or with a token
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
|
100
|
+
require 'pdfserve_client'
|
101
|
+
|
102
|
+
file_url = 'https://s3-public.de/file1.pdf'
|
103
|
+
pages = '1-3,4,6-8'
|
104
|
+
|
105
|
+
client = PdfserveClient::Client.new(api_endpoint: 'https://your.custom.endpoint', api_token: 'the-token')
|
106
|
+
client.split(file_url:, pages:)
|
107
|
+
```
|
108
|
+
|
109
|
+
`file_url` needs to be the url ( pdf) that need to be splitted
|
110
|
+
`pages` it needs to be comma separated page(s) range for splitting file into those pages.
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative "merge"
|
2
|
+
require_relative "stamp"
|
3
|
+
require_relative "split"
|
4
|
+
|
5
|
+
module PdfserveClient
|
6
|
+
class Client
|
7
|
+
attr_reader :merge_service, :stamp_service, :split_service
|
8
|
+
|
9
|
+
def initialize(api_endpoint:, api_token:)
|
10
|
+
@api_endpoint = api_endpoint
|
11
|
+
@api_token = api_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def merge(file_urls:, output_path:)
|
15
|
+
merge_service.merge(file_urls, output_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stamp(file_url:, stamp_text:)
|
19
|
+
stamp_service.call(file_url, stamp_text)
|
20
|
+
end
|
21
|
+
|
22
|
+
def split(file_url:, pages:)
|
23
|
+
split_service.split(file_url:, pages:)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def merge_service
|
29
|
+
PdfserveClient::Merge.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stamp_service
|
33
|
+
PdfserveClient::Stamp.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
34
|
+
end
|
35
|
+
|
36
|
+
def split_service
|
37
|
+
PdfserveClient::Split.new(api_endpoint: @api_endpoint, api_token: @api_token)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "version"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
module PdfserveClient
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class Merge
|
12
|
+
PATH = "/api/v1/pdf/merge"
|
13
|
+
|
14
|
+
def initialize(api_endpoint:, api_token: nil)
|
15
|
+
@api_endpoint = api_endpoint + PATH
|
16
|
+
@api_token = api_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def merge(file_urls, output_path)
|
20
|
+
uri = URI(api_endpoint)
|
21
|
+
request = Net::HTTP::Post.new(uri)
|
22
|
+
request["token"] = api_token unless api_token.nil?
|
23
|
+
form_data = file_urls.map { |url| ["files", url] }
|
24
|
+
|
25
|
+
request.set_form form_data, "multipart/form-data"
|
26
|
+
|
27
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
|
28
|
+
http.request(request)
|
29
|
+
end
|
30
|
+
|
31
|
+
if response.is_a?(Net::HTTPSuccess)
|
32
|
+
File.open(output_path, "wb") { |file| file.write(response.body) }
|
33
|
+
puts "Success!"
|
34
|
+
OpenStruct.new(success: true, errors: "")
|
35
|
+
else
|
36
|
+
puts "Failed!"
|
37
|
+
OpenStruct.new(success: false, errors: response.message)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :api_endpoint, :api_token
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "version"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
module PdfserveClient
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class Split
|
12
|
+
PATH = "/api/v1/pdf/split"
|
13
|
+
|
14
|
+
def initialize(api_endpoint:, api_token: nil)
|
15
|
+
@api_endpoint = api_endpoint + PATH
|
16
|
+
@api_token = api_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def split(file_url:, pages:)
|
20
|
+
uri = URI(api_endpoint)
|
21
|
+
uri.query = URI.encode_www_form({ pages: pages })
|
22
|
+
|
23
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
24
|
+
http.use_ssl = uri.scheme == "https"
|
25
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
26
|
+
|
27
|
+
request["token"] = api_token unless api_token.nil?
|
28
|
+
form_data = [["splitfile", file_url]]
|
29
|
+
|
30
|
+
request.set_form form_data, "multipart/form-data"
|
31
|
+
|
32
|
+
response = http.request(request)
|
33
|
+
|
34
|
+
if response.is_a?(Net::HTTPSuccess)
|
35
|
+
puts "Successful split!"
|
36
|
+
content_disposition = response.header["Content-Disposition"]
|
37
|
+
filename = content_disposition[/filename="?([^"]+)"?/, 1] || "archive.tar.gz"
|
38
|
+
|
39
|
+
OpenStruct.new(
|
40
|
+
success: true, response: response.read_body, filename: filename, errors: ""
|
41
|
+
)
|
42
|
+
else
|
43
|
+
puts "Failed!"
|
44
|
+
OpenStruct.new(
|
45
|
+
success: false, response: response.body, errors: response.message
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :api_endpoint, :api_token
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "version"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
module PdfserveClient
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class Stamp
|
12
|
+
PATH = "/api/v1/pdf/stamp"
|
13
|
+
|
14
|
+
def initialize(api_endpoint:, api_token: nil)
|
15
|
+
@api_endpoint = api_endpoint + PATH
|
16
|
+
@api_token = api_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(file_url, stamp_text)
|
20
|
+
uri = URI(api_endpoint)
|
21
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
22
|
+
http.use_ssl = uri.scheme == "https"
|
23
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
24
|
+
|
25
|
+
request["token"] = api_token unless api_token.nil?
|
26
|
+
form_data = [
|
27
|
+
["files", file_url],
|
28
|
+
["stamp_text", { "text" => stamp_text, "color" => "0,0,0", "position_name" => "tr", "over" => "true" }.to_json]
|
29
|
+
]
|
30
|
+
|
31
|
+
request.set_form form_data, "multipart/form-data"
|
32
|
+
|
33
|
+
response = http.request(request)
|
34
|
+
|
35
|
+
if response.is_a?(Net::HTTPSuccess)
|
36
|
+
puts "Successful stamp!"
|
37
|
+
OpenStruct.new(
|
38
|
+
success: true, response: response.body, errors: ""
|
39
|
+
)
|
40
|
+
else
|
41
|
+
puts "Failed!"
|
42
|
+
OpenStruct.new(
|
43
|
+
success: false, response: response.body, errors: response.message
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :api_endpoint, :api_token
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdfserve_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Isabel Garcia
|
8
|
+
- Antoine Legrand
|
9
|
+
- Lakhan Pasari
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2025-01-28 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: net-http
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.2.0
|
29
|
+
description: This gem provides a simple interface to merge, stamp, split PDFs using
|
30
|
+
https://github.com/ant31/pdfserve API.
|
31
|
+
email:
|
32
|
+
- isabel.garcia@conny.legal
|
33
|
+
- antoine.legrand@conny.legal
|
34
|
+
- lakhan.pasari@conny.legal
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- README.md
|
40
|
+
- lib/pdfserve_client.rb
|
41
|
+
- lib/pdfserve_client/client.rb
|
42
|
+
- lib/pdfserve_client/merge.rb
|
43
|
+
- lib/pdfserve_client/split.rb
|
44
|
+
- lib/pdfserve_client/stamp.rb
|
45
|
+
- lib/pdfserve_client/version.rb
|
46
|
+
homepage: https://github.com/mietright/pdf_merger
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.5.23
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A gem for merging, stamping, and splitting PDFs using an external API
|
69
|
+
test_files: []
|