B!VOIDNEON / BENTREF!JSON API
SPANK:BENTREF / VN-SPK-010

JSON API

Use BentRef!'s local JavaScript API from another page on the same website. The PDF is provided as base64 in a CODEX-style Packet. A Box returns a PDF payload, size data and a status. Files stay in the visitor's browser.

This is a browser JavaScript API, not a public HTTP endpoint. Server-to-server calls cannot run browser canvas rendering. No server PDF packages or services are needed or installed.

1 / Load the bundled engine

<script defer src="/bentref/assets/vendor/pdf-lib.min.js"></script>
<script type="module">
  import { jsonPacket } from '/bentref/compressor.js';
  // Call jsonPacket(packet) after your PDF bytes become base64.
</script>

2 / Packet

{
  "chain_id": "my-optional-reference",
  "act": "compress",
  "input": { "pdf_base64": "JVBERi0x..." },
  "options": {
    "mode": "visual",
    "colour": "gray",
    "dpi": 150,
    "quality": 0.72,
    "pages": "1-3,5",
    "targetMB": 2
  }
}

mode: preserve or visual. colour: colour, gray or bw (visual mode). dpi: 100, 150 or 200. quality: 0.35 to 0.92. Leave pages blank for all pages. Leave targetMB blank or zero for a single pass. Maximum input: 150 MB and 150 pages. Large base64 packets may need substantial browser memory. A target may trigger two further image-based passes.

3 / Result

{
  "ok": true,
  "chain_id": "my-optional-reference",
  "act": "compress",
  "state": "BOX SQUIRT",
  "input_bytes": 4800000,
  "output": {
    "pdf_base64": "JVBERi0x...",
    "mime_type": "application/pdf",
    "bytes": 1720000,
    "pages": 4,
    "mode": "visual",
    "target_met": true
  }
}

Errors return {"ok":false,"error":{"code":"COMPRESSION_FAILED","message":"..."}}. An invalid Packet returns INVALID_PACKET. BOX SQUIRT names the result in the VOIDNEON Acts and States CODEX; it is not an HTTP status.

Direct browser use

import {jsonPacket} from '/bentref/compressor.js';
const response = await jsonPacket(packet);
if (!response.ok) throw Error(response.error.message);
// Decode response.output.pdf_base64 to download or use the PDF.

If BentRef! is already loaded on the same page, window.BentRefAPI.call(packet) is also available. For large browser files, call compressBytes(bytes, options) directly to avoid the base64 overhead.

← BACK TO BENTREF!