selectpdf 1.3.0 → 1.6.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 +4 -4
- data/CHANGELOG.md +16 -1
- data/README.md +191 -4
- data/lib/selectpdf.rb +2088 -120
- data/samples/accessible_pdf.rb +69 -0
- data/samples/async_conversion.rb +48 -0
- data/samples/electronic_invoice.rb +106 -0
- data/samples/html_to_pdf_headers_and_footers.rb +5 -5
- data/samples/html_to_pdf_main.rb +40 -16
- data/samples/pdf_merge.rb +40 -0
- data/samples/pdf_to_text.rb +45 -0
- data/samples/search_pdf.rb +38 -0
- data/samples/simple_html_string_to_pdf.rb +2 -2
- data/samples/simple_url_to_pdf.rb +2 -2
- data/samples/web_elements.rb +42 -0
- metadata +16 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ae5074b6a4a0b0f2ce43d997aef9038b6167ef433d87398bf22b84e882a0712
|
|
4
|
+
data.tar.gz: d4db4d73e23f7208ca7bbd2d4cb98aa9a9532c44d93b5a0f788cd5cbf40cf835
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 582606dcd6800ed03da64f4205e9057a8371613c364aa278d6115270453fc40b6aa071ebfc4d5758c387949049a6e26bbb1a10655247d65b1f4f3e91e62d580b
|
|
7
|
+
data.tar.gz: '08773193c4235663f98870d7998b6646f6012e83a477f57deac1ff18facb7a6e75173d7f6c8001a39bbaa563bd3787e54f4769326b0664efdac3f873296c9e93'
|
data/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
+
### 1.6.0
|
|
2
|
+
* Includes the 1.5.0 features of the SelectPdf API clients (there was no separate 1.5.0 Ruby release).
|
|
3
|
+
* Accessible PDF and PDF standards on HtmlToPdfClient: tagged, pdf_standard (new SelectPdf::PdfStandard class: Full, PdfA, PdfA2B, PdfA3A, PdfA3B, PdfA3U, PdfX, PdfSiqQ_A, PdfSiqQ_B) and doc_language.
|
|
4
|
+
* Electronic invoices: new InvoiceClient creates ZUGFeRD / Factur-X hybrid invoices (PDF/A-3 with the invoice XML embedded) from a url or an html string, synchronously or asynchronously. Invoice XML from a file (invoice_xml_file) or from memory (invoice_xml), zugferd_profile, zugferd_relationship, zugferd_schema (new SelectPdf::ZugferdProfile, SelectPdf::ZugferdRelationship, SelectPdf::ZugferdSchema classes). Requires an API key.
|
|
5
|
+
* HtmlToPdfClient: web_page_fixed_size, auth_username, auth_password.
|
|
6
|
+
* 1.5.0: keyless demo mode - HtmlToPdfClient.new with no key, an empty key or 'demo' uses the demo endpoint (watermarked output, 5 pages, Chromium engine). New demo_mode?, demo_response?, clamped_fields, dropped_fields, was_clamped?, was_any_field_dropped?.
|
|
7
|
+
* 1.5.0: typed demo exceptions (subclasses of ApiException): DemoRateLimitException, DemoSafetyException, DemoUnsupportedException. user_password, owner_password and asynchronous calls raise DemoUnsupportedException in demo mode.
|
|
8
|
+
* 1.5.0: response telemetry on every client - credits_total, credits_remaining, mode, execution_mode.
|
|
9
|
+
* 1.5.0: SelectPdf::RenderingEngine::CHROMIUM.
|
|
10
|
+
* Number of pages and job id are read from the X-SelectPdf-Pages and X-SelectPdf-Job-Id response headers. Asynchronous jobs are complete when the job status is no longer 202 Accepted.
|
|
11
|
+
* Fixes: TRUE / FALSE constants (removed in Ruby 3.2) replaced with true / false, including the default arguments of the PdfToTextClient search methods; multipart requests (PDF merge, PDF to text) now send parameters set to false instead of skipping them; cookies are encoded with %20 for spaces, as the API expects.
|
|
12
|
+
|
|
13
|
+
### 1.4.0
|
|
14
|
+
* Pdf Merge Client, Pdf To Text Client
|
|
15
|
+
|
|
1
16
|
### 1.3.0
|
|
2
|
-
* Html To Pdf Client
|
|
17
|
+
* Html To Pdf Client
|
data/README.md
CHANGED
|
@@ -14,9 +14,10 @@ SelectPdf HTML To PDF Online REST API is a professional solution that lets you c
|
|
|
14
14
|
* Hide web page elements during the conversion.
|
|
15
15
|
* Automatically generate bookmarks during the html to pdf conversion.
|
|
16
16
|
* Support for partial page conversion.
|
|
17
|
-
*
|
|
17
|
+
* Tagged (accessible) PDF and PDF/A, PDF/X, PDF/SiqQ conformance.
|
|
18
|
+
* ZUGFeRD / Factur-X hybrid electronic invoices.
|
|
19
|
+
* Try it without an API key with the keyless demo endpoint.
|
|
18
20
|
* Works in all programming languages.
|
|
19
|
-
* No installation required.
|
|
20
21
|
|
|
21
22
|
Sign up for for free to get instant API access to SelectPdf [HTML to PDF API](https://selectpdf.com/html-to-pdf-api/).
|
|
22
23
|
|
|
@@ -34,11 +35,197 @@ Sign up for for free to get instant API access to SelectPdf [HTML to PDF API](ht
|
|
|
34
35
|
|
|
35
36
|
api.page_size = SelectPdf::PageSize::A4
|
|
36
37
|
api.margins = 0
|
|
37
|
-
api.page_numbers =
|
|
38
|
-
api.page_breaks_enhanced_algorithm =
|
|
38
|
+
api.page_numbers = false
|
|
39
|
+
api.page_breaks_enhanced_algorithm = true
|
|
39
40
|
|
|
40
41
|
api.convert_url_to_file(url, local_file)
|
|
41
42
|
rescue SelectPdf::ApiException => e
|
|
42
43
|
print("An error occurred: #{e}")
|
|
43
44
|
end
|
|
44
45
|
|
|
46
|
+
### Demo Mode (no API key)
|
|
47
|
+
|
|
48
|
+
Construct `HtmlToPdfClient` with no key, an empty key or `'demo'` to use the keyless demo endpoint. No signup is required, but the output is watermarked, capped at 5 pages and always rendered with the Chromium engine.
|
|
49
|
+
|
|
50
|
+
client = SelectPdf::HtmlToPdfClient.new # or HtmlToPdfClient.new('demo')
|
|
51
|
+
pdf = client.convert_url('https://selectpdf.com')
|
|
52
|
+
|
|
53
|
+
print "Demo mode: #{client.demo_mode?}, demo response: #{client.demo_response?}\n"
|
|
54
|
+
print "Clamped: #{client.clamped_fields.join(', ')}\n" if client.was_clamped?
|
|
55
|
+
print "Dropped: #{client.dropped_fields.join(', ')}\n" if client.was_any_field_dropped?
|
|
56
|
+
|
|
57
|
+
* `demo_mode?` - the client was constructed without a key. `demo_response?` - the last response came from the demo endpoint.
|
|
58
|
+
* `clamped_fields` - parameters the demo endpoint modified (e.g. `max_load_time` is capped to 15 seconds, `engine` is forced to Chromium).
|
|
59
|
+
* `dropped_fields` - parameters the demo endpoint ignored: `auth_username`, `auth_password`, `cookies_string` (set with `cookies`), `raw_parameters`, `pdf_name`, `async`, `pdf_web_elements_selectors`.
|
|
60
|
+
* PDF passwords (`user_password`, `owner_password`) and asynchronous calls are not available in demo mode and raise `SelectPdf::DemoUnsupportedException`.
|
|
61
|
+
* Only public urls are converted. Internal or private hosts are rejected with `SelectPdf::DemoSafetyException`.
|
|
62
|
+
* Per-IP and global rate limits raise `SelectPdf::DemoRateLimitException`.
|
|
63
|
+
|
|
64
|
+
### Exceptions
|
|
65
|
+
|
|
66
|
+
All errors raise `SelectPdf::ApiException`. The demo endpoint errors raise typed subclasses, so you can react to them without parsing the message:
|
|
67
|
+
|
|
68
|
+
| Exception | Raised when | Attributes |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `SelectPdf::DemoRateLimitException` | the demo rate limit is reached (HTTP 429 or 503) | `status_code`, `reason` (`per_ip`, `concurrency`, `daily_cap`), `retry_after`, `upgrade_url`, `response_body` |
|
|
71
|
+
| `SelectPdf::DemoSafetyException` | a url field references a non-public host (HTTP 400) | `status_code`, `field`, `reason`, `response_body` |
|
|
72
|
+
| `SelectPdf::DemoUnsupportedException` | a feature is not available in demo mode (HTTP 400, or before the request is sent with `status_code` 0) | `status_code`, `field`, `upgrade_url`, `response_body` |
|
|
73
|
+
|
|
74
|
+
begin
|
|
75
|
+
client = SelectPdf::HtmlToPdfClient.new
|
|
76
|
+
client.convert_url_to_file('https://selectpdf.com', 'Test.pdf')
|
|
77
|
+
rescue SelectPdf::DemoRateLimitException => e
|
|
78
|
+
print("Demo rate limit (#{e.reason}). Retry after #{e.retry_after}s. Upgrade: #{e.upgrade_url}\n")
|
|
79
|
+
rescue SelectPdf::DemoUnsupportedException => e
|
|
80
|
+
print("Feature '#{e.field}' not available in demo mode.\n")
|
|
81
|
+
rescue SelectPdf::ApiException => e
|
|
82
|
+
print("An error occurred: #{e}")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
### Response Telemetry
|
|
86
|
+
|
|
87
|
+
Every client exposes what the server reported for the most recent call:
|
|
88
|
+
|
|
89
|
+
* `number_of_pages` - number of pages of the resulted PDF.
|
|
90
|
+
* `credits_total` - monthly conversion limit of the subscription (-1 = unlimited, nil when not reported, e.g. in demo mode).
|
|
91
|
+
* `credits_remaining` - conversions remaining this month (-1 = unlimited, nil when not reported).
|
|
92
|
+
* `mode` - `production` or `demo`.
|
|
93
|
+
* `execution_mode` - server-side execution path of the conversion (e.g. `worker`).
|
|
94
|
+
|
|
95
|
+
### Accessible PDF and PDF Standards
|
|
96
|
+
|
|
97
|
+
client = SelectPdf::HtmlToPdfClient.new(api_key)
|
|
98
|
+
|
|
99
|
+
client.tagged = true # tagged (accessible) PDF - needs the Blink or Chromium engine
|
|
100
|
+
client.doc_title = 'Accessible document' # a tagged document needs a title
|
|
101
|
+
client.doc_language = 'en-US' # document language (PDF /Lang entry)
|
|
102
|
+
client.pdf_standard = SelectPdf::PdfStandard::PDF_A3A # Full, PdfA, PdfA2B, PdfA3A, PdfA3B, PdfA3U, PdfX, PdfSiqQ_A, PdfSiqQ_B
|
|
103
|
+
client.rendering_engine = SelectPdf::RenderingEngine::CHROMIUM # optional - the API promotes tagged requests to Chromium
|
|
104
|
+
|
|
105
|
+
client.convert_url_to_file('https://selectpdf.com', 'Accessible.pdf')
|
|
106
|
+
|
|
107
|
+
Other parameters added in 1.6.0:
|
|
108
|
+
|
|
109
|
+
* `web_page_fixed_size` - leave out the content below `web_page_height` instead of letting the page flow onto further pages.
|
|
110
|
+
* `auth_username`, `auth_password` - HTTP Basic authentication credentials for the web page being converted.
|
|
111
|
+
|
|
112
|
+
See [HTML to PDF API parameters](https://selectpdf.com/html-to-pdf-api-parameters/) for the full list of parameters.
|
|
113
|
+
|
|
114
|
+
## Electronic Invoice API
|
|
115
|
+
|
|
116
|
+
`SelectPdf::InvoiceClient` creates ZUGFeRD / Factur-X hybrid electronic invoices: one PDF/A-3 document carrying both the page a human reads and the invoice XML an accounting system reads. It derives from `HtmlToPdfClient`, so every conversion setting applies too. An API key is required - the demo endpoint does not create invoices.
|
|
117
|
+
|
|
118
|
+
### Features
|
|
119
|
+
|
|
120
|
+
* Create the visible invoice from a url or an html string, synchronously or asynchronously.
|
|
121
|
+
* Embed the invoice XML from a local file (`invoice_xml_file`) or from memory (`invoice_xml`).
|
|
122
|
+
* Profiles: `MINIMUM`, `BASIC_WL`, `BASIC`, `EN16931`, `EXTENDED`, `XRECHNUNG` (`SelectPdf::ZugferdProfile`).
|
|
123
|
+
* Optional relationship (`SelectPdf::ZugferdRelationship`) - derived from the profile when not set - and schema (`SelectPdf::ZugferdSchema`, Factur-X 1.0 by default).
|
|
124
|
+
* The carrier is PDF/A-3A by default; `PDF_A3B` and `PDF_A3U` are also accepted.
|
|
125
|
+
|
|
126
|
+
### Sample Code
|
|
127
|
+
|
|
128
|
+
require 'selectpdf'
|
|
129
|
+
|
|
130
|
+
api_key = 'Your API key here'
|
|
131
|
+
|
|
132
|
+
begin
|
|
133
|
+
client = SelectPdf::InvoiceClient.new(api_key)
|
|
134
|
+
|
|
135
|
+
client.invoice_xml_file = 'factur-x.xml' # or client.invoice_xml = xml_string
|
|
136
|
+
client.zugferd_profile = SelectPdf::ZugferdProfile::EN16931
|
|
137
|
+
# client.zugferd_relationship = SelectPdf::ZugferdRelationship::DATA # optional
|
|
138
|
+
# client.zugferd_schema = SelectPdf::ZugferdSchema::FACTUR_X_10 # optional
|
|
139
|
+
|
|
140
|
+
client.create_from_html_string_to_file('<h1>Invoice INV-2026-001</h1>', 'Invoice.pdf')
|
|
141
|
+
# client.create_from_url_to_file('https://your-app.example/invoices/INV-2026-001', 'Invoice.pdf')
|
|
142
|
+
# pdf = client.create_from_html_string_async('<h1>Invoice INV-2026-001</h1>')
|
|
143
|
+
|
|
144
|
+
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
145
|
+
rescue SelectPdf::ApiException => e
|
|
146
|
+
print("An error occurred: #{e}")
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
Available methods: `create_from_url`, `create_from_url_to_stream`, `create_from_url_to_file`, `create_from_html_string`, `create_from_html_string_with_base_url`, `create_from_html_string_to_stream`, `create_from_html_string_to_stream_with_base_url`, `create_from_html_string_to_file`, `create_from_html_string_with_base_url_to_file` and the asynchronous `create_from_url_async`, `create_from_url_to_stream_async`, `create_from_url_to_file_async`, `create_from_html_string_async`, `create_from_html_string_with_base_url_async`, `create_from_html_string_to_stream_async`, `create_from_html_string_to_file_async`.
|
|
150
|
+
|
|
151
|
+
See `samples/electronic_invoice.rb` for a complete sample with an inline invoice XML.
|
|
152
|
+
|
|
153
|
+
## Pdf Merge API
|
|
154
|
+
|
|
155
|
+
SelectPdf Pdf Merge REST API is an online solution that lets you merge local or remote PDFs into a final PDF document.
|
|
156
|
+
|
|
157
|
+
### Features
|
|
158
|
+
|
|
159
|
+
* Merge local PDF document.
|
|
160
|
+
* Merge remote PDF from public url.
|
|
161
|
+
* Set PDF viewer options and PDF document information.
|
|
162
|
+
* Secure generated PDF with a password.
|
|
163
|
+
* Works in all programming languages.
|
|
164
|
+
|
|
165
|
+
See [PDF Merge API](https://selectpdf.com/pdf-merge-api/) page for full list of parameters.
|
|
166
|
+
|
|
167
|
+
### Sample Code
|
|
168
|
+
|
|
169
|
+
require 'selectpdf'
|
|
170
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
171
|
+
|
|
172
|
+
test_url = 'https://selectpdf.com/demo/files/selectpdf.pdf'
|
|
173
|
+
test_pdf = 'Input.pdf'
|
|
174
|
+
local_file = 'Result.pdf'
|
|
175
|
+
api_key = 'Your API key here'
|
|
176
|
+
|
|
177
|
+
begin
|
|
178
|
+
client = SelectPdf::PdfMergeClient.new(api_key)
|
|
179
|
+
|
|
180
|
+
# specify the pdf files that will be merged (order will be preserved in the final pdf)
|
|
181
|
+
client.add_file(test_pdf) # add PDF from local file
|
|
182
|
+
client.add_url_file(test_url) # add PDF from public url
|
|
183
|
+
|
|
184
|
+
# merge pdfs to local file
|
|
185
|
+
client.save_to_file(local_file)
|
|
186
|
+
rescue SelectPdf::ApiException => e
|
|
187
|
+
print("An error occurred: #{e}")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
## Pdf To Text API
|
|
191
|
+
|
|
192
|
+
SelectPdf Pdf To Text REST API is an online solution that lets you extract text from your PDF documents or search your PDF document for certain words.
|
|
193
|
+
|
|
194
|
+
### Features
|
|
195
|
+
|
|
196
|
+
* Extract text from PDF.
|
|
197
|
+
* Search PDF.
|
|
198
|
+
* Specify start and end page for partial file processing.
|
|
199
|
+
* Specify output format (plain text or html).
|
|
200
|
+
* Use a PDF from an online location (url) or upload a local PDF document.
|
|
201
|
+
|
|
202
|
+
See [Pdf To Text API](https://selectpdf.com/pdf-to-text-api/) page for full list of parameters.
|
|
203
|
+
|
|
204
|
+
### Sample Code
|
|
205
|
+
|
|
206
|
+
require 'selectpdf'
|
|
207
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
208
|
+
|
|
209
|
+
test_pdf = 'Input.pdf'
|
|
210
|
+
local_file = 'Result.txt'
|
|
211
|
+
api_key = 'Your API key here'
|
|
212
|
+
|
|
213
|
+
begin
|
|
214
|
+
client = SelectPdf::PdfToTextClient.new(api_key)
|
|
215
|
+
|
|
216
|
+
# set parameters - see full list at https://selectpdf.com/pdf-to-text-api/
|
|
217
|
+
client.start_page = 1 # start page (processing starts from here)
|
|
218
|
+
client.end_page = 0 # end page (set 0 to process file til the end)
|
|
219
|
+
client.output_format = SelectPdf::OutputFormat::TEXT # set output format (Text or HTML)
|
|
220
|
+
|
|
221
|
+
print "Starting pdf to text ...\n"
|
|
222
|
+
|
|
223
|
+
# convert local pdf to local text file
|
|
224
|
+
client.text_from_file_to_file(test_pdf, local_file)
|
|
225
|
+
|
|
226
|
+
print "Finished! Number of pages processed: #{client.number_of_pages}.\n"
|
|
227
|
+
rescue SelectPdf::ApiException => e
|
|
228
|
+
print("An error occurred: #{e}")
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
|