Download the PHP package selectpdf/selectpdf-api-client without Composer
On this page you can find all versions of the php package selectpdf/selectpdf-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download selectpdf/selectpdf-api-client
More information about selectpdf/selectpdf-api-client
Files in selectpdf/selectpdf-api-client
Package selectpdf-api-client
Short Description PHP client for SelectPdf Online REST API: HTML to PDF, tagged / PDF/A output, ZUGFeRD / Factur-X electronic invoices, PDF merge and PDF to text
License MIT
Homepage https://selectpdf.com/html-to-pdf-api/
Informations about the package selectpdf-api-client
SelectPdf Online REST API - PHP Client
SelectPdf Online REST API is a professional solution for managing PDF documents online. It now has a dedicated, easy to use, PHP client library that can be setup in minutes.
Try without an API key (demo mode)
Demo mode limitations
Demo mode is intended for evaluating the API. To keep the public endpoint stable and prevent abuse, several limits and restrictions apply that don't exist on a paid endpoint.
Output:
- 5 pages maximum. Pages beyond the fifth are dropped, then a final branding/notice page is appended (so a typical demo PDF is 1-6 pages depending on the source).
- Watermarked. A SelectPdf demo stamp is rendered on every page plus a footer attribution line.
- Chromium rendering engine only. If you call
setRenderingEngine(...)withWebKit,RestrictedorBlink, the server switches toChromium. The response reports it:wasClamped()returns true andgetClampedFields()includesengine.
Not available in demo mode (the client throws DemoUnsupportedException before the request is sent):
| Method | Behavior in demo mode |
|---|---|
setUserPassword(...) / setOwnerPassword(...) |
Throws DemoUnsupportedException (field user_password / owner_password). |
convert*Async(...) |
Throws DemoUnsupportedException (field async). The demo endpoint is synchronous only. |
getWebElements() |
Throws DemoUnsupportedException (field pdf_web_elements_selectors). |
Clamped parameters: setNavigationTimeout(...) (max_load_time) is capped to 15 seconds and setConversionDelay(...) (min_load_time) to 5 seconds. The capped field names are listed by getClampedFields().
Silently dropped fields: auth_username / auth_password, cookies_string (setCookies(...)), pdf_name and pdf_web_elements_selectors are accepted but never honored by the demo endpoint. Any value you set is reported back by wasAnyFieldDropped() / getDroppedFields(). Clamped means the value was modified, dropped means it was thrown away.
URLs: the demo endpoint accepts only publicly reachable http:// / https:// URLs. Requests targeting non-public destinations are rejected with DemoSafetyException (HTTP 400).
Rate limits: per-IP, daily global and concurrency limits apply. A request over a limit is rejected with DemoRateLimitException; getReason() is per_ip, daily_cap or concurrency, and getRetryAfter() carries the Retry-After header value in seconds.
Request size: the request body is capped at 1 MB (HTTP 413) - typically only an issue if you inline a very large HTML string.
Response: no credit headers (the demo endpoint is keyless, so there is no billing account): getCreditsTotal() and getCreditsRemaining() return null. getMode() returns "demo" (helper: isDemoResponse()).
Catching demo-mode errors
The client has three typed exceptions for demo-specific failures, all derived from ApiException; everything else surfaces as a regular ApiException:
Every demo exception also exposes getStatusCode() and getResponseBody() (the raw JSON error body returned by the server).
For unwatermarked production output without these limits, pass a real API key - same client class, same setters:
isDemoMode() is set at construction time and stays the same for the client's lifetime, so a client created with a real key never falls back to demo behavior.
Installation
Download selectpdf-api-php-client-1.6.0.zip, unzip it and require SelectPdf.Api.php in your code.
OR
Install SelectPdf PHP Client for Online API from Packagist: SelectPdf API on Packagist.
OR
Clone selectpdf-api-php-client from Github and require SelectPdf.Api.php in your code.
HTML To PDF API - PHP Client
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. The API is easy to use and the integration takes only a few lines of code.
Features
- Create PDF from any web page or html string.
- Full html5/css3/javascript support.
- Set PDF options such as page size and orientation, margins, security, web page settings.
- Set PDF viewer options and PDF document information.
- Create custom headers and footers for the pdf document.
- Hide web page elements during the conversion.
- Automatically generate bookmarks during the html to pdf conversion.
- Support for partial page conversion.
- Produce tagged, accessible PDF and target a PDF/A, PDF/X or PDF/SiqQ conformance level.
- Easy integration, no third party libraries needed.
- Works in all programming languages.
- No installation required.
Sign up for for free to get instant API access to SelectPdf HTML to PDF API.
Sample Code
More conversion options
Asynchronous conversions
Use the *Async methods for long-running conversions. The client starts the job and polls /api2/asyncjob/ every AsyncCallsPingInterval seconds, up to AsyncCallsMaxPings times.
Web elements
Get the location in the generated PDF of the HTML elements that match a set of CSS selectors.
Response telemetry
Every client reports what the server returned with the most recent call:
| Method | Value |
|---|---|
getNumberOfPages() |
Number of pages of the resulted PDF (X-SelectPdf-Pages). |
getCreditsTotal() |
Monthly conversion limit of the subscription (X-SelectPdf-Credits-Total). -1 = unlimited. Null if absent (demo endpoint, error response). |
getCreditsRemaining() |
Conversions remaining this month (X-SelectPdf-Credits-Remaining). -1 = unlimited. Null if absent. |
getMode() |
"production" or "demo" (X-SelectPdf-Mode). Empty if absent. |
getExecutionMode() |
"in-process" or "worker" (X-SelectPdf-Execution). Empty for endpoints that do not convert. |
HtmlToPdfClient also has isDemoMode(), isDemoResponse(), getClampedFields() / wasClamped() and getDroppedFields() / wasAnyFieldDropped() (see demo mode above).
Accessible PDF and PDF Standards
Produce a tagged, accessible PDF and target a PDF conformance level, using the same HtmlToPdfClient you already use for conversions.
Features
- Tagged PDF with a logical structure tree: headings, paragraphs, lists, tables, figures with alternate text, links and reading order.
- Document language written as the PDF
/Langentry and onto the tagged structure elements. - PDF/A for long term archiving, PDF/X for graphics exchange, PDF/SiqQ for documents that will be digitally signed.
- PDF/A-3A is the accessible archival level and implies a tagged document on its own.
Tagged output requires the Blink or Chromium rendering engine - the WebKit engines cannot build a structure tree. If you do not set an engine, the API promotes the conversion to Chromium and reports the engine it used in the X-SelectPdf-Engine response header. Asking for tagged output together with an explicit WebKit engine is rejected rather than silently producing an untagged PDF.
Note this produces tagged PDF/A output; it is not a conformance certification.
Sample Code - Accessible PDF
Electronic Invoicing API - ZUGFeRD / Factur-X
Turn an HTML invoice into a hybrid electronic invoice: one PDF/A-3 file carrying both the invoice a human reads and the XML a recipient's accounting system reads, embedded as an associated file with the metadata invoice software looks for.
Features
- Profiles MINIMUM, BASIC WL, BASIC, EN 16931, EXTENDED and XRECHNUNG (
ZugferdProfileconstants). - The attachment relationship (
ZugferdRelationship) is derived from the profile when you do not set one. - The embedded file is named as the standard requires -
factur-x.xml, orxrechnung.xmlfor the XRECHNUNG profile - because recipients look it up by name. - Factur-X 1.0 metadata by default; the deprecated ZUGFeRD 2.0 schema (
ZugferdSchema::Zugferd20) is available for recipients that still require it. - Carrier defaults to PDF/A-3A, the accessible level, so the visible invoice is readable by assistive technology as well as archivable. PdfA3B and PdfA3U are also accepted.
- Every HTML to PDF conversion setting applies, because
InvoiceClientderives fromHtmlToPdfClient.
The invoice XML can only be embedded into a document created as PDF/A-3, so there is no variant that attaches it to an existing PDF you already have. An API key is required - the keyless demo endpoint does not produce electronic invoices, and InvoiceClient refuses a missing or "demo" key.
Use the createFrom* methods: createFromUrl, createFromHtmlString, createFromHtmlStringWithBaseUrl, each with ToStream / ToFile variants and Async variants (for example createFromHtmlStringToFileAsync).
Sample Code - Electronic Invoice
Pdf Merge API
SelectPdf Pdf Merge REST API is an online solution that lets you merge local or remote PDFs into a final PDF document.
Features
- Merge local PDF document.
- Merge remote PDF from public url.
- Set PDF viewer options and PDF document information.
- Secure generated PDF with a password.
- Works in all programming languages.
See PDF Merge API page for full list of parameters.
Sample Code
Pdf To Text 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.
Features
- Extract text from PDF.
- Search PDF.
- Specify start and end page for partial file processing.
- Specify output format (plain text or html).
- Use a PDF from an online location (url) or upload a local PDF document.
See Pdf To Text API page for full list of parameters.
Sample Code - Pdf To Text
Sample Code - Search Pdf
Changelog
1.6.0
Includes the 1.5.0 changes listed below (there was no separate 1.5.0 release of the PHP client).
- New
InvoiceClientfor ZUGFeRD / Factur-X hybrid electronic invoices (POST/api2/invoice/): converts a url or an html invoice into a PDF/A-3 document with the invoice XML embedded as an associated file. MethodssetInvoiceXmlFile,setInvoiceXml,setZugferdProfile,setZugferdRelationship,setZugferdSchemaandcreateFromUrl/createFromHtmlString/createFromHtmlStringWithBaseUrlwithToStream,ToFileandAsyncvariants. Profiles MINIMUM, BASIC WL, BASIC, EN 16931, EXTENDED and XRECHNUNG, with the attachment relationship derived from the profile when not set. Requires an API key. - Accessibility and standards on
HtmlToPdfClient:setTagged(tagged, accessible PDF - requires the Blink or Chromium engine; the API promotes the engine automatically when none is set),setPdfStandard(Full, PdfA, PdfA2B, PdfA3A, PdfA3B, PdfA3U, PdfX, PdfSiqQ_A, PdfSiqQ_B) andsetDocumentLanguage. setWebPageFixedSize(cut the page at the web page height or convert the whole page) andsetAuthUsername/setAuthPassword(HTTP Basic authentication on the converted page).- New constants classes:
PdfStandard,ZugferdProfile,ZugferdRelationship,ZugferdSchema. setPageSizeaccepts A0, A6, A7 and A8 (thePageSizeconstants already existed).- Fixed
convertUrlToStream, which did not pass the output stream to the request. - Requires PHP 7.1 or newer (the library already used PHP 7.1 syntax; composer.json now says so).
1.5.0 (included in 1.6.0)
- Keyless demo mode:
new HtmlToPdfClient()(or a null, empty or "demo" key) converts with the public demo endpoint - no signup, watermarked output, 5-page cap, Chromium engine.isDemoMode(),isDemoResponse(),getClampedFields()/wasClamped(),getDroppedFields()/wasAnyFieldDropped(). - Typed demo exceptions derived from
ApiException:DemoRateLimitException,DemoSafetyException,DemoUnsupportedException.setUserPassword,setOwnerPassword, the async conversions andgetWebElementsthrowDemoUnsupportedExceptionin demo mode. - Response telemetry on every client:
getCreditsTotal(),getCreditsRemaining(),getMode(),getExecutionMode(), read from theX-SelectPdf-*response headers. RenderingEngine::Chromium.