Web SDKv1.0.0

PDFDocument.fromUrlProgressive()

Open over HTTP range requests, before the whole file has arrived: the viewer appears and the first pages become viewable after a small fraction of the file has downloaded, while the rest streams in the background. Works best with linearized ("fast web view") PDFs but benefits any PDF. Requires a server that honors Range requests (checked automatically; falls back to a normal full download when it does not).

Until isFullyLoaded is true the document is view-only: the editing tools are grayed out, and undo snapshots, page management, search and export wait for completion (whenFullyLoaded()). Form fields can be filled meanwhile. The document API does not wait: save(), pages.extract() and every write through its namespaces reject with INVALID_STATE until then. Pages scrolled to before their bytes arrive download on demand (ensurePageAvailable() — the viewer does this automatically for pages and thumbnails).

static methodLoadingsince 1.0.0

Signature

static fromUrlProgressive(url: string, options?: OpenProgressiveOptions): Promise<PDFDocument>

Parameters

ParameterTypeDescription
urlstringThe URL to open over HTTP range requests.
options?OpenProgressiveOptionsWhat fromUrl takes (every range request carries headers, credentials and signal) plus chunkSize (range-request size in bytes, default 256 KiB) and onProgress ((downloaded, total) => void).

Returns

Promise<PDFDocument>

Throws

  • ABORTED — the signal was aborted.
  • CORS_ERROR — the server did not allow the page's origin.
  • NETWORK_ERROR — the request failed, or the progressive download could not finish.
  • NOT_INITIALIZED — Kernstra.init() has not resolved.
  • FORMAT_ERROR — not a PDF, or a corrupt one.
  • PASSWORD_ERROR — a password is required, or the one supplied is wrong.
  • SECURITY_ERROR — encrypted with a security handler the SDK cannot open.
  • LICENSE_REQUIRED — opened under a stopped license: no document opens.

Example

TypeScript
const doc = await PDFDocument.fromUrlProgressive('/big-report.pdf', {
  chunkSize: 256 * 1024, // range-request size (default 256 KiB)
  onProgress: (loaded, total) => updateProgressBar(loaded / total),
});

More in PDFDocument