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).
Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
| url | string | The URL to open over HTTP range requests. |
| options? | OpenProgressiveOptions | What 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— thesignalwas 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
const doc = await PDFDocument.fromUrlProgressive('/big-report.pdf', { chunkSize: 256 * 1024, // range-request size (default 256 KiB) onProgress: (loaded, total) => updateProgressBar(loaded / total), });