PdfHttpByteSource class

A PdfByteSource that reads a remote PDF over HTTP(S), using Range requests when the server supports them and transparently falling back to a single full download when it does not.

Pass headers for authentication (e.g. Authorization) or content negotiation. On the web, cross-origin loads are subject to CORS: the server must send Access-Control-Allow-Origin and, for Range-based progressive loading, expose Accept-Ranges/Content-Range via Access-Control-Expose-Headers; otherwise the browser hides them and this source falls back to a full download. To send cookies cross-origin, supply a BrowserClient()..withCredentials = true as client.

Use with PdfDocument.openSource / CosDocument.openSource:

final source = PdfHttpByteSource(Uri.parse('https://host/big.pdf'),
    headers: {'Authorization': 'Bearer $token'}, cancelToken: token);
final document = await PdfDocument.openSource(source);
Implemented types

Constructors

PdfHttpByteSource(Uri uri, {Map<String, String>? headers, Client? client, PdfCancelToken? cancelToken, void onProgress(int received, int? total)?})

Properties

cancelToken PdfCancelToken?
Optional cancellation handle.
final
hashCode int
The hash code for this object.
no setterinherited
length Future<int?>
The total number of bytes, or null when the length is not known ahead of time (e.g. a server that answers neither HEAD nor a ranged GET with a total). A null length makes progressive loading fall back to a plain sequential download.
no setteroverride
onProgress → void Function(int received, int? total)?
Called after each network read with the running total of bytes received and the document length once known.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportsRange bool
Whether the server answered the probe with a 206 (Range supported). Only meaningful after the first read; false when the source fell back to a full download. Useful for diagnostics and tests.
no setter
uri Uri
The document URL.
final

Methods

close() Future<void>
Releases any resources (open connections, buffers). Optional; the default does nothing. Sources are single-use unless documented otherwise.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readRange(int start, int endExclusive) Future<Uint8List>
Returns the bytes in [start, endExclusive). Implementations clamp the range to the available data: a request past the end returns fewer bytes (a short read), and a request wholly past the end returns an empty list. start is clamped to be non-negative; endExclusive <= start yields an empty list.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited