Skip to content
PressJetDocs Docs v0.1.0-beta.9 GitHub
Edit this page
Source docs v0.1.0-beta.9 Install v0.1.0-beta.7
On this page

SDK design

Every Pressjet SDK offers the same two things, written the way its language expects:

  1. Builders that make a document tree (spec/document.schema.json) without writing JSON.
  2. A client that sends requests to a Pressjet server (spec/openapi.yaml) and turns answers and refusals into values and typed errors.

The HTTP API and the document format are the contract. SDKs add no behavior the server lacks and never hide a server refusal.

Package names

Language Package Import
TypeScript / JavaScript npm pressjet import { Pressjet, document, page } from "pressjet"
Go github.com/tonysantana1492/pressjet/sdks/go import "github.com/tonysantana1492/pressjet/sdks/go" (package pressjet)
PHP Composer pressjet/pressjet use Pressjet\Client;
Python PyPI pressjet import pressjet

Dependencies and runtimes

  • No runtime dependencies beyond the language's standard library (PHP may require ext-curl and ext-json). Users can inject their own HTTP client where the language has a standard interface.
  • TypeScript runs on Node 22+, Deno, Bun, browsers and edge runtimes: it uses fetch, Uint8Array and AbortSignal, never Node-only APIs.
  • Go 1.26+. PHP 8.3+. Python 3.11+ with type hints and py.typed.
  • The minimums are the oldest versions their projects still support. When one reaches its end of life, the next release raises the minimum and the CI matrix with it.

Local export in Node.js

The pressjet/local entry point exports renderLocal(document, options?). It sends the same versioned document as generate to a short-lived native process and returns the PDF as a Uint8Array. The executable receives embedded images only. Release packages use an exact-version optional dependency for the host CPU on Linux. Applications can also supply the executable. Usage and configuration

Client

Configuration (names adapted to each language's style):

Option Default Meaning
apiKey PRESSJET_API_KEY environment variable Sent as Authorization: Bearer <key>.
baseUrl PRESSJET_URL environment variable, else http://localhost:8080 The server origin.
timeout 60 seconds For the whole request, including retries.
maxRetries 2 Retries after 429, 502, 503, 504 and connection failures.
maxResponseBytes 128 MiB Larger answers fail instead of filling memory.
headers none Extra headers on every request.

The environment fallbacks apply only where an environment exists (not in browsers).

The built-in HTTP transports return redirects as failures without forwarding a request.

Rendering is a pure function of the request, so every operation is safe to retry. Retries wait for Retry-After when the server sends it, otherwise 0.5 s × 2^attempt with ±25% jitter, capped at 8 s, and never past the timeout. Every request sends User-Agent: pressjet-<language>/<version> (not in browsers, which forbid it) and a fresh X-Request-Id.

Methods (each takes per-call options to override the timeout and add headers, where idiomatic):

Method Request Returns
generate(document) POST /v1/generate {version, layout} PDF bytes
html(html, settings?) POST /v1/html with version, populated HTML and optional stylesheets, images, omissions, font family, fonts, profile, conformance, created, lang and engine PDF bytes
preview(document, options?) POST /v1/preview {version, layout, options} (options default {}) { pdf: bytes, totalPages, pages: [{ pageNumber, width, height, png: bytes }] }
check(document, fonts?) POST /v1/check {version, layout, fonts?}; the document may be any JSON value { ok, pageCount, pages: [{ number, width, height, filled }], diagnostics: [{ code, severity, pointer, page?, message, fix, ...details }], dropped, anchors? }
checkHtml(html, settings?) POST /v1/check with an HTML body as for html (without engine) the same report, the compiler's findings first
draw(flow, appendPdfs?) POST /v1/draw {version, flow, appendPdfs?} PDF bytes
merge(pdfs) POST /v1/merge {version, pdfs} PDF bytes
overlay(pdf, marks, fonts?) POST /v1/overlay {version, pdf, marks, fonts?} PDF bytes
rasterize(bytes, options?) POST /v1/rasterize {version, bytes, options} { totalPages, pages } as in preview
sign(pdf, { name, reason, signingTime }) POST /v1/sign PDF bytes
signing group POST /v1/signing/* (no version member) see Signing
info() GET /v1/info the server's capabilities
health() GET /health { status, version }

Binary inputs accept the language's byte type; the SDK base64-encodes them. A string input is passed through unchanged (it is already base64 or a data: URL). signingTime accepts the language's date-time type and is sent as RFC 3339 in UTC. The answer's page images are decoded from their data:image/png;base64, URLs into bytes.

Each SDK also offers a multipart HTML call for raw JPEG and PNG attachments. Use htmlMultipart in TypeScript and PHP, HTMLMultipart in Go and html_multipart in Python. Pass the HTML, a mapping from image src to bytes, and optional print settings. The request uses the native engine and the same retry policy as JSON. See binary HTML images for the naming and size limits.

Signing

The signing group wraps the stateless /v1/signing/* routes: pressjet.signing in TypeScript, client.Signing() in Go, $client->signing() in PHP and client.signing in Python. It has eleven methods over ten routes, because prepare is split by input:

Method Route Returns
prepareTemplate /v1/signing/prepare with templateId {revision, pdf: bytes}
preparePdf /v1/signing/prepare with pdf and fields the revision
open, revoke, void /open, /revoke, /void a transition {envelope, events, effects}
decide /decide {receipt, transition}; transition is null for a decision already recorded
seal /seal {transition, pdf: bytes, evidence: bytes}
view /view the signer's view
voidCopy /void-copy PDF bytes
effects /effects the effects due now
verify /verify nothing; a refusal raises

verify sends the events it is given, an empty list as []: the server then checks the chain and refuses event_chain_broken for any envelope that has events. Leaving the events out checks only the seal. Go's Verify always sends its events (nil as []) and adds VerifySeal for the seal alone.

Envelopes, revisions and events are opaque. A method that takes one sends back the same JSON value it received; typed access is a view over that value, never a rebuild. The usual retries apply, because the routes keep no state. See Signing with your own database.

Errors

  • PressjetError (or the idiomatic equivalent) for every problem answer, with status, code, title, detail (optional), requestId and retryAfter (seconds, optional). Its message reads "<title>: <detail> (<code>, request <requestId>)". Constants or an enum list every code from spec/openapi.yaml.
  • An answer that is not a problem document still produces a PressjetError with code http_<status>.
  • A layout report with errors is a value, never an exception: check raises only for the same failures as every other call. Diagnostic codes are listed as constants or an enum (spec/check.schema.json), and the code field stays a plain string so a newer server's codes still read.
  • A connection failure or timeout raises a distinct error type (PressjetConnectionError, PressjetTimeoutError or the language's convention) that keeps the underlying cause.

Builders

document({ title?, author? }, ...pages)
page({ size?, style? }, ...children)
view({ style?, fixed?, wrap?, break?, keepTogether? }, ...children)
text({ style?, fixed?, wrap?, break? }, ...children)   children: strings, numbers, text, image
image({ src, style?, fixed?, wrap?, break? })           src: bytes, base64 or a data: URL
pageNumber(template = "{pageNumber} / {totalPages}", { style?, fixed = true })  a text node
  • Children that are null, undefined, false or the language's "nothing" are dropped, and nested lists are flattened, so conditional content reads naturally.
  • Numbers inside text become strings.
  • Properties left unset are omitted, never sent as null.
  • Every node is a plain value of the shape { type, properties, children } that serializes to the schema without further work.
  • A Style type lists every style property with its allowed values (from spec/document.schema.json), so editors complete and check them.

Conformance

Every SDK has a test that builds spec/fixtures/invoice.document.json with its builders and checks that the result equals the fixture as JSON. The fixture uses every builder. It is built this way:

document({ title: "Invoice INV-001", author: "Pressjet" },
  page({ size: "A4", style: { padding: 40, fontFamily: "Helvetica", fontSize: 10, color: "#111827" } },
    view({ fixed: true, style: { flexDirection: "row", justifyContent: "space-between", marginBottom: 24 } },
      image({ src: <the PNG bytes of the fixture's base64>, style: { width: 48, height: 48 } }),
      text({ style: { fontSize: 20, fontWeight: "bold" } }, "Invoice")),
    text({}, "Billed to ", text({ style: { fontWeight: "bold" } }, "Acme Corp.")),
    view({ wrap: false, style: { borderTopWidth: 1, borderTopColor: "#e5e7eb", paddingTop: 8, marginTop: 16 } },
      view({ style: { flexDirection: "row" } },
        text({ style: { flex: 1 } }, "Design work"),
        text({ style: { width: 80, textAlign: "right" } }, "$1,200.00"))),
    text({ break: true }, "Terms and conditions"),
    pageNumber("Page {pageNumber} of {totalPages}",
      { style: { position: "absolute", bottom: 20, right: 40, fontSize: 8 } })))

Passing the image as bytes proves the SDK encodes bytes as standard padded base64.

Integration tests run against a real server when PRESSJET_TEST_URL and PRESSJET_TEST_API_KEY are set, and are skipped otherwise. They cover every operation with the fixtures (check reproduces the codes and pointers of spec/fixtures/defects.report.json), an invalid_document refusal whose detail names a JSON Pointer, and an unauthorized refusal. Unit tests cover retries and Retry-After against a local fake server.

generate, preview and check also take request fonts: { family?, weight?, style?, src } with src as bytes the SDK encodes. Each SDK passes them in its own option style.