selectpdf 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8eaf046e0be6119e542567c9aaa8619c54e7f6c99819a84c9d96f2b7b38d21af
4
- data.tar.gz: 3cab0ed9984ebd11cfa25dde675327a94ffd37203e9e35e57932910fbd5e956f
3
+ metadata.gz: 7ae5074b6a4a0b0f2ce43d997aef9038b6167ef433d87398bf22b84e882a0712
4
+ data.tar.gz: d4db4d73e23f7208ca7bbd2d4cb98aa9a9532c44d93b5a0f788cd5cbf40cf835
5
5
  SHA512:
6
- metadata.gz: 106e81246f60e07de4cd302133b317624c79784b852974fb77092d3d31ea28d11dc74ec29bda1552c48cb4f7473f0457a42fd187c18893a9d2d9cdc9fa2a83d7
7
- data.tar.gz: 026b2222f8282cbf80f0e5b8a8684d0de2ea4a3eb366bb39638175088dcfb75549f9f46d259a08ec205a1df51f6a778c5968c305fab961656c04b9204b7b63ed
6
+ metadata.gz: 582606dcd6800ed03da64f4205e9057a8371613c364aa278d6115270453fc40b6aa071ebfc4d5758c387949049a6e26bbb1a10655247d65b1f4f3e91e62d580b
7
+ data.tar.gz: '08773193c4235663f98870d7998b6646f6012e83a477f57deac1ff18facb7a6e75173d7f6c8001a39bbaa563bd3787e54f4769326b0664efdac3f873296c9e93'
data/CHANGELOG.md CHANGED
@@ -1,5 +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
+
1
13
  ### 1.4.0
2
14
  * Pdf Merge Client, Pdf To Text Client
3
15
 
4
16
  ### 1.3.0
5
- * Html To Pdf Client
17
+ * Html To Pdf Client
data/README.md CHANGED
@@ -14,6 +14,9 @@ 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
+ * 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.
17
20
  * Works in all programming languages.
18
21
 
19
22
  Sign up for for free to get instant API access to SelectPdf [HTML to PDF API](https://selectpdf.com/html-to-pdf-api/).
@@ -32,14 +35,121 @@ Sign up for for free to get instant API access to SelectPdf [HTML to PDF API](ht
32
35
 
33
36
  api.page_size = SelectPdf::PageSize::A4
34
37
  api.margins = 0
35
- api.page_numbers = FALSE
36
- api.page_breaks_enhanced_algorithm = TRUE
38
+ api.page_numbers = false
39
+ api.page_breaks_enhanced_algorithm = true
37
40
 
38
41
  api.convert_url_to_file(url, local_file)
39
42
  rescue SelectPdf::ApiException => e
40
43
  print("An error occurred: #{e}")
41
44
  end
42
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
+
43
153
  ## Pdf Merge API
44
154
 
45
155
  SelectPdf Pdf Merge REST API is an online solution that lets you merge local or remote PDFs into a final PDF document.