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
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
# Tagged (accessible) PDF and PDF conformance standards.
|
|
4
|
+
|
|
5
|
+
$stdout.sync = true
|
|
6
|
+
|
|
7
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
8
|
+
|
|
9
|
+
url = 'https://selectpdf.com'
|
|
10
|
+
local_file = 'Accessible.pdf'
|
|
11
|
+
|
|
12
|
+
# Works with the keyless demo endpoint too - set the key to nil or 'demo'.
|
|
13
|
+
# Note the demo stamps its output after conversion, so a demo PDF demonstrates
|
|
14
|
+
# the feature rather than being a conformant artifact; use a real key for output you intend to ship.
|
|
15
|
+
api_key = 'Your API key here'
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
client = SelectPdf::HtmlToPdfClient.new(api_key)
|
|
19
|
+
|
|
20
|
+
# set parameters - see full list at https://selectpdf.com/html-to-pdf-api-parameters/
|
|
21
|
+
|
|
22
|
+
# Produce a tagged PDF: a logical structure tree covering headings, paragraphs, lists, tables,
|
|
23
|
+
# figures with alternate text, links and reading order - what a screen reader needs to read the document.
|
|
24
|
+
client.tagged = true
|
|
25
|
+
|
|
26
|
+
# A tagged document needs a title. Without this the converter falls back to the HTML <title>.
|
|
27
|
+
client.doc_title = 'SelectPdf - accessible sample'
|
|
28
|
+
|
|
29
|
+
# Shown by viewers that honour it; accessible PDF expects it on, and the API turns it on
|
|
30
|
+
# for you whenever tagged output is requested.
|
|
31
|
+
client.viewer_display_doc_title = true
|
|
32
|
+
|
|
33
|
+
# The document language, written as the PDF /Lang entry and onto the tagged structure elements.
|
|
34
|
+
client.doc_language = 'en-US'
|
|
35
|
+
|
|
36
|
+
# Conformance target. PdfA3A is the ACCESSIBLE level of PDF/A-3: it implies a tagged document on its own,
|
|
37
|
+
# and it is the level required to carry a ZUGFeRD / Factur-X invoice (see electronic_invoice.rb).
|
|
38
|
+
# FULL - the complete PDF feature set (default)
|
|
39
|
+
# PDF_A / PDF_A2B / PDF_A3B / PDF_A3U - long term archiving
|
|
40
|
+
# PDF_A3A - archiving + accessibility
|
|
41
|
+
# PDF_X - graphics exchange
|
|
42
|
+
# PDF_SIQQ_A / PDF_SIQQ_B - digital signatures
|
|
43
|
+
client.pdf_standard = SelectPdf::PdfStandard::PDF_A3A
|
|
44
|
+
|
|
45
|
+
# Tagged output requires the Blink or Chromium engine - the WebKit engines cannot build a structure tree.
|
|
46
|
+
# You can name one explicitly:
|
|
47
|
+
#
|
|
48
|
+
# client.rendering_engine = SelectPdf::RenderingEngine::CHROMIUM
|
|
49
|
+
#
|
|
50
|
+
# If you don't, the API promotes the conversion to Chromium for you and reports the engine it used
|
|
51
|
+
# in the X-SelectPdf-Engine response header. Asking for tagged output together with an explicit WebKit
|
|
52
|
+
# engine is rejected with HTTP 400 rather than silently producing an untagged PDF.
|
|
53
|
+
|
|
54
|
+
print "Starting conversion ...\n"
|
|
55
|
+
|
|
56
|
+
# convert url to local file
|
|
57
|
+
client.convert_url_to_file(url, local_file)
|
|
58
|
+
|
|
59
|
+
# convert url to memory
|
|
60
|
+
# pdf = client.convert_url(url)
|
|
61
|
+
|
|
62
|
+
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
63
|
+
|
|
64
|
+
# response telemetry
|
|
65
|
+
print "Mode: #{client.mode}, Execution: #{client.execution_mode}.\n"
|
|
66
|
+
print "Credits remaining: #{client.credits_remaining} / #{client.credits_total}.\n"
|
|
67
|
+
rescue SelectPdf::ApiException => e
|
|
68
|
+
print("An error occurred: #{e}")
|
|
69
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
$stdout.sync = true
|
|
4
|
+
|
|
5
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
6
|
+
|
|
7
|
+
url = 'https://selectpdf.com'
|
|
8
|
+
local_file = 'Test.pdf'
|
|
9
|
+
|
|
10
|
+
# Async conversions are not supported on the demo endpoint - this sample requires a paid API key.
|
|
11
|
+
api_key = 'Your API key here'
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
client = SelectPdf::HtmlToPdfClient.new(api_key)
|
|
15
|
+
|
|
16
|
+
# Tune polling for the async job (optional).
|
|
17
|
+
# The client polls /api2/asyncjob/ every async_calls_ping_interval seconds,
|
|
18
|
+
# up to async_calls_max_pings times, then gives up.
|
|
19
|
+
client.async_calls_ping_interval = 3 # seconds between polls
|
|
20
|
+
client.async_calls_max_pings = 1000 # max polls before timeout
|
|
21
|
+
|
|
22
|
+
client.page_size = SelectPdf::PageSize::A4
|
|
23
|
+
client.page_orientation = SelectPdf::PageOrientation::PORTRAIT
|
|
24
|
+
client.margins = 0
|
|
25
|
+
client.page_breaks_enhanced_algorithm = true
|
|
26
|
+
|
|
27
|
+
print "Starting async conversion ...\n"
|
|
28
|
+
|
|
29
|
+
# url to file (async)
|
|
30
|
+
client.convert_url_to_file_async(url, local_file)
|
|
31
|
+
|
|
32
|
+
# url to memory (async)
|
|
33
|
+
# pdf = client.convert_url_async(url)
|
|
34
|
+
|
|
35
|
+
# html string to file (async)
|
|
36
|
+
# client.convert_html_string_to_file_async('This is some <b>html</b>.', local_file)
|
|
37
|
+
|
|
38
|
+
# html string to memory (async)
|
|
39
|
+
# pdf = client.convert_html_string_async('This is some <b>html</b>.')
|
|
40
|
+
|
|
41
|
+
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
42
|
+
|
|
43
|
+
# response telemetry
|
|
44
|
+
print "Mode: #{client.mode}, Execution: #{client.execution_mode}.\n"
|
|
45
|
+
print "Credits remaining: #{client.credits_remaining} / #{client.credits_total}.\n"
|
|
46
|
+
rescue SelectPdf::ApiException => e
|
|
47
|
+
print("An error occurred: #{e}")
|
|
48
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
# ZUGFeRD / Factur-X hybrid electronic invoice.
|
|
4
|
+
|
|
5
|
+
$stdout.sync = true
|
|
6
|
+
|
|
7
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
8
|
+
|
|
9
|
+
# A minimal, well-formed EN 16931 CrossIndustryInvoice, inline so the sample runs without any extra files.
|
|
10
|
+
# A real integration produces this from its own invoice data - the API embeds the bytes as given
|
|
11
|
+
# and does not validate the invoice content.
|
|
12
|
+
invoice_xml = '<?xml version="1.0" encoding="UTF-8"?>' \
|
|
13
|
+
'<rsm:CrossIndustryInvoice' \
|
|
14
|
+
' xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"' \
|
|
15
|
+
' xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"' \
|
|
16
|
+
' xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">' \
|
|
17
|
+
'<rsm:ExchangedDocumentContext>' \
|
|
18
|
+
'<ram:GuidelineSpecifiedDocumentContextParameter>' \
|
|
19
|
+
'<ram:ID>urn:cen.eu:en16931:2017</ram:ID>' \
|
|
20
|
+
'</ram:GuidelineSpecifiedDocumentContextParameter>' \
|
|
21
|
+
'</rsm:ExchangedDocumentContext>' \
|
|
22
|
+
'<rsm:ExchangedDocument>' \
|
|
23
|
+
'<ram:ID>INV-2026-001</ram:ID>' \
|
|
24
|
+
'<ram:TypeCode>380</ram:TypeCode>' \
|
|
25
|
+
'<ram:IssueDateTime>' \
|
|
26
|
+
'<udt:DateTimeString format="102">20260924</udt:DateTimeString>' \
|
|
27
|
+
'</ram:IssueDateTime>' \
|
|
28
|
+
'</rsm:ExchangedDocument>' \
|
|
29
|
+
'</rsm:CrossIndustryInvoice>'
|
|
30
|
+
|
|
31
|
+
invoice_html = '<html><head><title>Invoice INV-2026-001</title></head><body>' \
|
|
32
|
+
'<h1>Invoice INV-2026-001</h1>' \
|
|
33
|
+
'<p>Seller Ltd — Buyer GmbH</p>' \
|
|
34
|
+
'<table>' \
|
|
35
|
+
'<tr><th>Item</th><th>Total</th></tr>' \
|
|
36
|
+
'<tr><td>Consulting</td><td>1000.00 EUR</td></tr>' \
|
|
37
|
+
'</table>' \
|
|
38
|
+
'</body></html>'
|
|
39
|
+
|
|
40
|
+
local_file = 'Invoice.pdf'
|
|
41
|
+
|
|
42
|
+
# Electronic invoices require an API key - the keyless demo endpoint does not produce them,
|
|
43
|
+
# and InvoiceClient refuses a demo key rather than failing later on the server.
|
|
44
|
+
api_key = 'Your API key here'
|
|
45
|
+
|
|
46
|
+
begin
|
|
47
|
+
client = SelectPdf::InvoiceClient.new(api_key)
|
|
48
|
+
|
|
49
|
+
# set parameters - see full list at https://selectpdf.com/html-to-pdf-api-parameters/#invoicing
|
|
50
|
+
|
|
51
|
+
# The invoice XML. From memory here; from disk with
|
|
52
|
+
# client.invoice_xml_file = 'factur-x.xml'
|
|
53
|
+
# Either way the name recorded inside the PDF is the one the standard prescribes - recipients
|
|
54
|
+
# look it up by name, so it is not taken from your file name.
|
|
55
|
+
client.invoice_xml = invoice_xml
|
|
56
|
+
|
|
57
|
+
# How much of the EN 16931 model the XML carries. Required.
|
|
58
|
+
# MINIMUM / BASIC_WL - not complete invoices
|
|
59
|
+
# BASIC / EN16931 / EXTENDED - complete, increasing detail
|
|
60
|
+
# XRECHNUNG - German public sector; the embedded file is then named xrechnung.xml instead of factur-x.xml
|
|
61
|
+
client.zugferd_profile = SelectPdf::ZugferdProfile::EN16931
|
|
62
|
+
|
|
63
|
+
# Optional. Left unset, the API derives the relationship from the profile: Alternative for Minimum and Basic_WL,
|
|
64
|
+
# where the visible page carries more than the XML, and Data for the rest, where both carry the same content -
|
|
65
|
+
# which Germany mandates for BASIC, EN 16931, EXTENDED and XRECHNUNG. Minimum or Basic_WL combined with Data
|
|
66
|
+
# is rejected, because it would not be true.
|
|
67
|
+
#
|
|
68
|
+
# client.zugferd_relationship = SelectPdf::ZugferdRelationship::DATA
|
|
69
|
+
|
|
70
|
+
# Optional. Factur-X 1.0 is the current schema and the default;
|
|
71
|
+
# ZUGFeRD 2.0 is deprecated and only for recipients that require it.
|
|
72
|
+
#
|
|
73
|
+
# client.zugferd_schema = SelectPdf::ZugferdSchema::ZUGFERD_20
|
|
74
|
+
|
|
75
|
+
# The carrier must be PDF/A-3. It defaults to PdfA3A, the accessible level, which the standards recommend
|
|
76
|
+
# because it also makes the visible invoice readable by assistive technology. PdfA3B and PdfA3U are accepted;
|
|
77
|
+
# anything else is rejected.
|
|
78
|
+
#
|
|
79
|
+
# client.pdf_standard = SelectPdf::PdfStandard::PDF_A3B
|
|
80
|
+
|
|
81
|
+
# Every ordinary conversion setting applies here as well, because InvoiceClient derives from HtmlToPdfClient.
|
|
82
|
+
client.margins = 20
|
|
83
|
+
|
|
84
|
+
print "Starting invoice conversion ...\n"
|
|
85
|
+
|
|
86
|
+
# create the hybrid invoice from raw html, into a local file
|
|
87
|
+
client.create_from_html_string_to_file(invoice_html, local_file)
|
|
88
|
+
|
|
89
|
+
# ... or from the invoice page your application already renders
|
|
90
|
+
# client.create_from_url_to_file('https://your-app.example/invoices/INV-2026-001', local_file)
|
|
91
|
+
|
|
92
|
+
# ... or into memory
|
|
93
|
+
# pdf = client.create_from_html_string(invoice_html)
|
|
94
|
+
|
|
95
|
+
# ... or asynchronously, for long invoice runs
|
|
96
|
+
# client.create_from_html_string_to_file_async(invoice_html, local_file)
|
|
97
|
+
|
|
98
|
+
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
99
|
+
print "Wrote #{local_file} - a PDF/A-3 document with factur-x.xml embedded.\n"
|
|
100
|
+
|
|
101
|
+
# response telemetry
|
|
102
|
+
print "Mode: #{client.mode}, Execution: #{client.execution_mode}.\n"
|
|
103
|
+
print "Credits remaining: #{client.credits_remaining} / #{client.credits_total}.\n"
|
|
104
|
+
rescue SelectPdf::ApiException => e
|
|
105
|
+
print("An error occurred: #{e}")
|
|
106
|
+
end
|
|
@@ -14,22 +14,22 @@ begin
|
|
|
14
14
|
# set parameters - see full list at https://selectpdf.com/html-to-pdf-api/
|
|
15
15
|
|
|
16
16
|
client.margins = 0 # PDF page margins
|
|
17
|
-
client.page_breaks_enhanced_algorithm =
|
|
17
|
+
client.page_breaks_enhanced_algorithm = true # enhanced page break algorithm
|
|
18
18
|
|
|
19
19
|
# header properties
|
|
20
|
-
client.show_header =
|
|
20
|
+
client.show_header = true # display header
|
|
21
21
|
# client.header_height = 50 # header height
|
|
22
22
|
# client.header_url = url # header url
|
|
23
23
|
client.header_html = 'This is the <b>HEADER</b>!!!!' # header html
|
|
24
24
|
|
|
25
25
|
# footer properties
|
|
26
|
-
client.show_footer =
|
|
26
|
+
client.show_footer = true # display footer
|
|
27
27
|
# client.footer_height = 60 # footer height
|
|
28
28
|
# client.footer_url = url # footer url
|
|
29
29
|
client.footer_html = 'This is the <b>FOOTER</b>!!!!' # footer html
|
|
30
30
|
|
|
31
31
|
# footer page numbers
|
|
32
|
-
client.page_numbers =
|
|
32
|
+
client.page_numbers = true # show page numbers in footer
|
|
33
33
|
client.page_numbers_template = '{page_number} / {total_pages}' # page numbers template
|
|
34
34
|
client.page_numbers_font_name = 'Verdanda' # page numbers font name
|
|
35
35
|
client.page_numbers_font_size = 12 # page numbers font size
|
|
@@ -53,7 +53,7 @@ begin
|
|
|
53
53
|
|
|
54
54
|
# get API usage
|
|
55
55
|
usage_client = SelectPdf::UsageClient.new(api_key)
|
|
56
|
-
usage = usage_client.get_usage(
|
|
56
|
+
usage = usage_client.get_usage(false)
|
|
57
57
|
print("Usage: #{usage}\n")
|
|
58
58
|
print('Conversions remained this month: ', usage['available'], "\n")
|
|
59
59
|
rescue SelectPdf::ApiException => e
|
data/samples/html_to_pdf_main.rb
CHANGED
|
@@ -8,6 +8,11 @@ url = 'https://selectpdf.com'
|
|
|
8
8
|
local_file = 'Test.pdf'
|
|
9
9
|
api_key = 'Your API key here'
|
|
10
10
|
|
|
11
|
+
# Use nil, '' or 'demo' as the key to use the keyless demo endpoint
|
|
12
|
+
# (output is watermarked, capped at 5 pages, Chromium engine only).
|
|
13
|
+
# Replace it with a real key for full production output.
|
|
14
|
+
# api_key = nil
|
|
15
|
+
|
|
11
16
|
begin
|
|
12
17
|
client = SelectPdf::HtmlToPdfClient.new(api_key)
|
|
13
18
|
|
|
@@ -16,22 +21,22 @@ begin
|
|
|
16
21
|
client.page_size = SelectPdf::PageSize::A4 # PDF page size
|
|
17
22
|
client.page_orientation = SelectPdf::PageOrientation::PORTRAIT # PDF page orientation
|
|
18
23
|
client.margins = 0 # PDF page margins
|
|
19
|
-
client.rendering_engine = SelectPdf::RenderingEngine::WEBKIT # rendering engine
|
|
24
|
+
client.rendering_engine = SelectPdf::RenderingEngine::WEBKIT # rendering engine (demo mode forces Chromium)
|
|
20
25
|
client.conversion_delay = 1 # conversion delay
|
|
21
26
|
client.navigation_timeout = 30 # navigation timeout
|
|
22
|
-
client.page_numbers =
|
|
23
|
-
client.page_breaks_enhanced_algorithm =
|
|
27
|
+
client.page_numbers = false # page numbers
|
|
28
|
+
client.page_breaks_enhanced_algorithm = true # enhanced page break algorithm
|
|
24
29
|
|
|
25
30
|
# additional properties
|
|
26
31
|
|
|
27
|
-
# client.use_css_print =
|
|
28
|
-
# client.disable_javascript =
|
|
29
|
-
# client.disable_internal_links =
|
|
30
|
-
# client.disable_external_links =
|
|
31
|
-
# client.keep_images_together =
|
|
32
|
-
# client.scale_images =
|
|
33
|
-
# client.single_page_pdf =
|
|
34
|
-
# client.user_password = 'password' # secure the PDF with a password
|
|
32
|
+
# client.use_css_print = true # enable CSS media print
|
|
33
|
+
# client.disable_javascript = true # disable javascript
|
|
34
|
+
# client.disable_internal_links = true # disable internal links
|
|
35
|
+
# client.disable_external_links = true # disable external links
|
|
36
|
+
# client.keep_images_together = true # keep images together
|
|
37
|
+
# client.scale_images = true # scale images to create smaller pdfs
|
|
38
|
+
# client.single_page_pdf = true # generate a single page PDF
|
|
39
|
+
# client.user_password = 'password' # secure the PDF with a password (paid keys only)
|
|
35
40
|
|
|
36
41
|
# generate automatic bookmarks
|
|
37
42
|
|
|
@@ -54,11 +59,30 @@ begin
|
|
|
54
59
|
|
|
55
60
|
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
56
61
|
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
# response telemetry
|
|
63
|
+
print "Mode: #{client.mode}, Execution: #{client.execution_mode}.\n"
|
|
64
|
+
|
|
65
|
+
if client.demo_mode?
|
|
66
|
+
print "Demo clamped: #{client.clamped_fields.join(', ')}.\n" if client.was_clamped?
|
|
67
|
+
print "Demo dropped: #{client.dropped_fields.join(', ')}.\n" if client.was_any_field_dropped?
|
|
68
|
+
else
|
|
69
|
+
print "Credits remaining: #{client.credits_remaining} / #{client.credits_total}.\n"
|
|
70
|
+
|
|
71
|
+
# get API usage (paid keys only - the demo endpoint has no usage account)
|
|
72
|
+
usage_client = SelectPdf::UsageClient.new(api_key)
|
|
73
|
+
usage = usage_client.get_usage(false)
|
|
74
|
+
print("Usage: #{usage}\n")
|
|
75
|
+
print('Conversions remained this month: ', usage['available'], "\n")
|
|
76
|
+
end
|
|
77
|
+
rescue SelectPdf::DemoRateLimitException => e
|
|
78
|
+
# reason is one of: per_ip, daily_cap, concurrency
|
|
79
|
+
print("Demo rate limit (#{e.reason}). Retry after #{e.retry_after}s. Upgrade: #{e.upgrade_url}\n")
|
|
80
|
+
rescue SelectPdf::DemoSafetyException => e
|
|
81
|
+
# the demo only converts public urls - internal/private hosts are rejected
|
|
82
|
+
print("Demo safety guard rejected '#{e.field}' (reason=#{e.reason}).\n")
|
|
83
|
+
rescue SelectPdf::DemoUnsupportedException => e
|
|
84
|
+
# feature not available on the demo endpoint (e.g. user_password)
|
|
85
|
+
print("Feature '#{e.field}' not available in demo mode. Upgrade: #{e.upgrade_url}\n")
|
|
62
86
|
rescue SelectPdf::ApiException => e
|
|
63
87
|
print("An error occurred: #{e}")
|
|
64
88
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
$stdout.sync = true
|
|
4
|
+
|
|
5
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
6
|
+
|
|
7
|
+
test_url = 'https://selectpdf.com/demo/files/selectpdf.pdf'
|
|
8
|
+
test_pdf = 'Input.pdf'
|
|
9
|
+
local_file = 'Result.pdf'
|
|
10
|
+
api_key = 'Your API key here'
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
client = SelectPdf::PdfMergeClient.new(api_key)
|
|
14
|
+
|
|
15
|
+
# set parameters - see full list at https://selectpdf.com/pdf-merge-api/
|
|
16
|
+
|
|
17
|
+
# specify the pdf files that will be merged (order will be preserved in the final pdf)
|
|
18
|
+
client.add_file(test_pdf) # add PDF from local file
|
|
19
|
+
client.add_url_file(test_url) # add PDF from public url
|
|
20
|
+
# client.add_file(test_pdf, 'pdf_password') # add PDF (that requires a password) from local file
|
|
21
|
+
# client.add_url_file(test_url, 'pdf_password') # add PDF (that requires a password) from public url
|
|
22
|
+
|
|
23
|
+
print "Starting pdf merge ...\n"
|
|
24
|
+
|
|
25
|
+
# merge pdfs to local file
|
|
26
|
+
client.save_to_file(local_file)
|
|
27
|
+
|
|
28
|
+
# merge pdfs to memory
|
|
29
|
+
# pdf = client.save
|
|
30
|
+
|
|
31
|
+
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
32
|
+
|
|
33
|
+
# get API usage
|
|
34
|
+
usage_client = SelectPdf::UsageClient.new(api_key)
|
|
35
|
+
usage = usage_client.get_usage(false)
|
|
36
|
+
print("Usage: #{usage}\n")
|
|
37
|
+
print('Conversions remained this month: ', usage['available'], "\n")
|
|
38
|
+
rescue SelectPdf::ApiException => e
|
|
39
|
+
print("An error occurred: #{e}")
|
|
40
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
$stdout.sync = true
|
|
4
|
+
|
|
5
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
6
|
+
|
|
7
|
+
test_url = 'https://selectpdf.com/demo/files/selectpdf.pdf'
|
|
8
|
+
test_pdf = 'Input.pdf'
|
|
9
|
+
local_file = 'Result.txt'
|
|
10
|
+
api_key = 'Your API key here'
|
|
11
|
+
|
|
12
|
+
begin
|
|
13
|
+
client = SelectPdf::PdfToTextClient.new(api_key)
|
|
14
|
+
|
|
15
|
+
# set parameters - see full list at https://selectpdf.com/pdf-to-text-api/
|
|
16
|
+
client.start_page = 1 # start page (processing starts from here)
|
|
17
|
+
client.end_page = 0 # end page (set 0 to process file til the end)
|
|
18
|
+
client.output_format = SelectPdf::OutputFormat::TEXT # set output format (Text or HTML)
|
|
19
|
+
|
|
20
|
+
print "Starting pdf to text ...\n"
|
|
21
|
+
|
|
22
|
+
# convert local pdf to local text file
|
|
23
|
+
client.text_from_file_to_file(test_pdf, local_file)
|
|
24
|
+
|
|
25
|
+
# extract text from local pdf to memory
|
|
26
|
+
# text = client.text_from_file(test_pdf)
|
|
27
|
+
# print text
|
|
28
|
+
|
|
29
|
+
# convert pdf from public url to local text file
|
|
30
|
+
# client.text_from_url_to_file(test_url, local_file)
|
|
31
|
+
|
|
32
|
+
# extract text from pdf from public url to memory
|
|
33
|
+
# text = client.text_from_url(test_url)
|
|
34
|
+
# print text
|
|
35
|
+
|
|
36
|
+
print "Finished! Number of pages processed: #{client.number_of_pages}.\n"
|
|
37
|
+
|
|
38
|
+
# get API usage
|
|
39
|
+
usage_client = SelectPdf::UsageClient.new(api_key)
|
|
40
|
+
usage = usage_client.get_usage(false)
|
|
41
|
+
print("Usage: #{usage}\n")
|
|
42
|
+
print('Conversions remained this month: ', usage['available'], "\n")
|
|
43
|
+
rescue SelectPdf::ApiException => e
|
|
44
|
+
print("An error occurred: #{e}")
|
|
45
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
$stdout.sync = true
|
|
4
|
+
|
|
5
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
6
|
+
|
|
7
|
+
test_url = 'https://selectpdf.com/demo/files/selectpdf.pdf'
|
|
8
|
+
test_pdf = 'Input.pdf'
|
|
9
|
+
api_key = 'Your API key here'
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
client = SelectPdf::PdfToTextClient.new(api_key)
|
|
13
|
+
|
|
14
|
+
# set parameters - see full list at https://selectpdf.com/pdf-to-text-api/
|
|
15
|
+
client.start_page = 1 # start page (processing starts from here)
|
|
16
|
+
client.end_page = 0 # end page (set 0 to process file til the end)
|
|
17
|
+
client.output_format = SelectPdf::OutputFormat::TEXT # set output format (Text or HTML)
|
|
18
|
+
|
|
19
|
+
print "Starting search pdf ...\n"
|
|
20
|
+
|
|
21
|
+
# search local pdf
|
|
22
|
+
results = client.search_file(test_pdf, 'pdf')
|
|
23
|
+
|
|
24
|
+
# search pdf from public url
|
|
25
|
+
# results = client.search_url(test_url, 'pdf')
|
|
26
|
+
|
|
27
|
+
print "Search results: #{results}.\nSearch results count: #{results.length}\n"
|
|
28
|
+
|
|
29
|
+
print "Finished! Number of pages processed: #{client.number_of_pages}.\n"
|
|
30
|
+
|
|
31
|
+
# get API usage
|
|
32
|
+
usage_client = SelectPdf::UsageClient.new(api_key)
|
|
33
|
+
usage = usage_client.get_usage(false)
|
|
34
|
+
print("Usage: #{usage}\n")
|
|
35
|
+
print('Conversions remained this month: ', usage['available'], "\n")
|
|
36
|
+
rescue SelectPdf::ApiException => e
|
|
37
|
+
print("An error occurred: #{e}")
|
|
38
|
+
end
|
|
@@ -10,8 +10,8 @@ begin
|
|
|
10
10
|
|
|
11
11
|
api.page_size = SelectPdf::PageSize::A4
|
|
12
12
|
api.margins = 0
|
|
13
|
-
api.page_numbers =
|
|
14
|
-
api.page_breaks_enhanced_algorithm =
|
|
13
|
+
api.page_numbers = false
|
|
14
|
+
api.page_breaks_enhanced_algorithm = true
|
|
15
15
|
|
|
16
16
|
api.convert_html_string_to_file(html, local_file)
|
|
17
17
|
rescue SelectPdf::ApiException => e
|
|
@@ -10,8 +10,8 @@ begin
|
|
|
10
10
|
|
|
11
11
|
api.page_size = SelectPdf::PageSize::A4
|
|
12
12
|
api.margins = 0
|
|
13
|
-
api.page_numbers =
|
|
14
|
-
api.page_breaks_enhanced_algorithm =
|
|
13
|
+
api.page_numbers = false
|
|
14
|
+
api.page_breaks_enhanced_algorithm = true
|
|
15
15
|
|
|
16
16
|
api.convert_url_to_file(url, local_file)
|
|
17
17
|
rescue SelectPdf::ApiException => e
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'selectpdf'
|
|
2
|
+
|
|
3
|
+
$stdout.sync = true
|
|
4
|
+
|
|
5
|
+
print "This is SelectPdf-#{SelectPdf::CLIENT_VERSION}\n"
|
|
6
|
+
|
|
7
|
+
url = 'https://selectpdf.com'
|
|
8
|
+
local_file = 'Test.pdf'
|
|
9
|
+
|
|
10
|
+
# Web elements lookup requires a paid API key (the demo endpoint does not expose the elements service).
|
|
11
|
+
api_key = 'Your API key here'
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
client = SelectPdf::HtmlToPdfClient.new(api_key)
|
|
15
|
+
|
|
16
|
+
# CSS selectors used to identify HTML elements whose location in the resulting PDF
|
|
17
|
+
# should be reported back. See the API docs for selector syntax: https://selectpdf.com/html-to-pdf-api/
|
|
18
|
+
client.page_size = SelectPdf::PageSize::A4
|
|
19
|
+
client.margins = 0
|
|
20
|
+
client.pdf_web_elements_selectors = 'H1, H2, *.menu, *#footer'
|
|
21
|
+
|
|
22
|
+
print "Starting conversion ...\n"
|
|
23
|
+
|
|
24
|
+
client.convert_url_to_file(url, local_file)
|
|
25
|
+
|
|
26
|
+
print "Finished! Number of pages: #{client.number_of_pages}.\n"
|
|
27
|
+
|
|
28
|
+
# Retrieve element rectangles. Returns an empty list if no element matched the configured selectors.
|
|
29
|
+
elements = client.web_elements
|
|
30
|
+
print "Web elements found: #{elements.length}.\n"
|
|
31
|
+
|
|
32
|
+
elements.each do |element|
|
|
33
|
+
rectangles = element['PdfRectangles'] || []
|
|
34
|
+
print " - <#{element['HtmlElementTagName']}> id='#{element['HtmlElementId']}' " \
|
|
35
|
+
"class='#{element['HtmlElementCssClassName']}' rectangles=#{rectangles.length}\n"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
print "Mode: #{client.mode}, Execution: #{client.execution_mode}.\n"
|
|
39
|
+
print "Credits remaining: #{client.credits_remaining} / #{client.credits_total}.\n"
|
|
40
|
+
rescue SelectPdf::ApiException => e
|
|
41
|
+
print("An error occurred: #{e}")
|
|
42
|
+
end
|
metadata
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: selectpdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SelectPdf
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: |2
|
|
14
13
|
SelectPdf Online REST API is a professional solution for managing PDF documents online.
|
|
15
14
|
SelectPdf cloud API consists of the following:
|
|
16
15
|
HTML to PDF REST API – SelectPdf HTML To PDF Online REST API is a professional solution that lets you create PDF from web pages and raw HTML code in your applications.
|
|
16
|
+
Electronic Invoice REST API – SelectPdf Invoice REST API creates ZUGFeRD / Factur-X hybrid electronic invoices: a PDF/A-3 document with the invoice XML embedded.
|
|
17
|
+
PDF to TEXT REST API – 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.
|
|
18
|
+
PDF Merge REST API – SelectPdf Pdf Merge REST API is an online solution that lets you merge local or remote PDFs into a final PDF document.
|
|
17
19
|
email: support@selectpdf.com
|
|
18
20
|
executables: []
|
|
19
21
|
extensions: []
|
|
@@ -22,15 +24,21 @@ files:
|
|
|
22
24
|
- CHANGELOG.md
|
|
23
25
|
- README.md
|
|
24
26
|
- lib/selectpdf.rb
|
|
27
|
+
- samples/accessible_pdf.rb
|
|
28
|
+
- samples/async_conversion.rb
|
|
29
|
+
- samples/electronic_invoice.rb
|
|
25
30
|
- samples/html_to_pdf_headers_and_footers.rb
|
|
26
31
|
- samples/html_to_pdf_main.rb
|
|
32
|
+
- samples/pdf_merge.rb
|
|
33
|
+
- samples/pdf_to_text.rb
|
|
34
|
+
- samples/search_pdf.rb
|
|
27
35
|
- samples/simple_html_string_to_pdf.rb
|
|
28
36
|
- samples/simple_url_to_pdf.rb
|
|
37
|
+
- samples/web_elements.rb
|
|
29
38
|
homepage: https://selectpdf.com/html-to-pdf-api/
|
|
30
39
|
licenses:
|
|
31
40
|
- MIT
|
|
32
41
|
metadata: {}
|
|
33
|
-
post_install_message:
|
|
34
42
|
rdoc_options: []
|
|
35
43
|
require_paths:
|
|
36
44
|
- lib
|
|
@@ -45,9 +53,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
45
53
|
- !ruby/object:Gem::Version
|
|
46
54
|
version: '0'
|
|
47
55
|
requirements: []
|
|
48
|
-
rubygems_version: 3.
|
|
49
|
-
signing_key:
|
|
56
|
+
rubygems_version: 3.6.9
|
|
50
57
|
specification_version: 4
|
|
51
|
-
summary: SelectPdf Online REST API client library for Ruby. Contains
|
|
52
|
-
|
|
58
|
+
summary: SelectPdf Online REST API client library for Ruby. Contains HTML to PDF converter,
|
|
59
|
+
ZUGFeRD / Factur-X electronic invoices, PDF merge, PDF to text extractor, search
|
|
60
|
+
PDF.
|
|
53
61
|
test_files: []
|