DocsEnginesDocument LifecycleOpen Document from URL

openDocumentUrl

Opens a PDF document from a given URL by downloading the entire file.

Signature

openDocumentUrl(file: PdfFileUrl, options?: PdfOpenDocumentUrlOptions): PdfTask<PdfDocumentObject>;

Description

This function initiates the process of loading a PDF file from a remote URL. It fetches the complete file content into memory before opening it.

💡

Note on Loading Strategy Currently, this function always downloads the entire PDF file. Support for progressive loading via HTTP range requests is planned for a future release. The mode option is reserved for this future enhancement and will have no effect on the current behavior.

Parameters

NameTypeDescription
filePdfFileUrlAn object containing a unique id you provide and the url of the PDF file. Example: { id: 'unique-doc-id', url: 'https://example.com/document.pdf' }
optionsPdfOpenDocumentUrlOptions(Optional) An object to configure loading. Can include a password for encrypted files.

PdfOpenDocumentUrlOptions

export interface PdfOpenDocumentUrlOptions { password?: string; /** * NOTE: This option is reserved for future use. Currently, only the 'full-fetch' * behavior is implemented regardless of the selected mode. */ mode?: 'auto' | 'range-request' | 'full-fetch'; }

Returns

PdfTask<PdfDocumentObject>

A Task that resolves with a PdfDocumentObject when the document is successfully opened. The PdfDocumentObject contains metadata about the PDF, such as the page count and the dimensions of each page.

If the operation fails (e.g., the URL is invalid, the file is corrupted, or the password is incorrect), the Task will be rejected with a PdfErrorReason.

See Concepts: Tasks for more on how to handle asynchronous operations.

Example

// Assuming 'engine' is an initialized PdfiumEngine instance const fileUrl = { id: 'my-doc', url: '/path/to/document.pdf' }; try { // Use .toPromise() to work with async/await const document = await engine.openDocumentUrl(fileUrl, { password: 'my-secret-password' }).toPromise(); console.log(`Successfully opened document with ${document.pageCount} pages.`); // Now you can use the 'document' object with other engine methods // e.g., engine.renderPage(document, document.pages[0]); } catch (error) { console.error('Failed to open document:', error); }

See Also

Last updated on August 14, 2025

Need Help?

Join our community for support, discussions, and to contribute to EmbedPDF's development.