> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/uwp/viewer/view-online-pdfs.md).

# Open and Stream PDF from URL in UWP PDF Viewer

Efficiently open & stream PDFs from URL in UWP with Apryse Technology that allows partial content online PDF viewing.

Online PDFs can be viewed the same way as one can stream an online video. For example, you can see the beginning of the content almost immediately, and if you move to the middle of the content, it is prioritized and loaded very quickly, before other parts. Showing partial PDF content while downloading on demand provides fast and responsive PDF viewing experience. While most viewers require the entire file to be downloaded before it can be opened and viewed, with Apryse technology, viewing partial content for online PDF is made simple.

## Requirements

Due to the variety of PDF files and their hosting source, not every PDF can be viewed before the entire file is downloaded. To make this happen, the following are required:

* A linearized (fast web view) PDF document.
* A web server that supports byte-range requests (otherwise known as byte serving).
* Apryse's `OpenUrlAsync` method.

## Make a linearized PDF document

A linearized document has two important properties:

1. Its internal structure is organized so that pages are arranged from beginning to end and a page's data is all in the same area, and
2. the document has a "linearization dictionary" and "hint tables" that list the location and size of all internal objects at the beginning of the PDF file

Apryse SDK can linearize new and and existing PDF documents when they are saved. Once you have a `PDFDoc` object (by either opening an existing PDF or creating a new one), it can be saved with the `e_linearized` flag, for example:

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
PDFDoc pdfdoc = new PDFDoc("in.pdf");
pdfdoc.SaveAsync("out.pdf", pdftron.SDF.SDFDocSaveOptions.e_linearized);
```

{% endcode %}
{% endtab %}
{% endtabs %}

Another potential option is to use Acrobat to save a document for "Fast Web View", which will also linearize a document.

## Byte-range requests

Secondly, a web server that supports byte-range requests is required. A byte-range request asks the server to send a certain set of bytes from a file that don't necessarily start from byte zero or comprise the entire file. For example if the HTTP GET headers include the following key value pair

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
Range: bytes=1495454-1594723
```

{% endcode %}
{% endtab %}
{% endtabs %}

\~97 KB will be sent from the requested file by a byte-range supporting server, starting at byte 1495454.

To test whether your webserver supports this feature, use cURL on your favourite \*nix system (or using the [native Windows version](http://curl.haxx.se/dlwiz/?type=bin\&os=Win32\&flav=-\&ver=2000/XP)) as follows:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
curl -H Range:bytes=16- -I https://www.pdftron.com
```

{% endcode %}
{% endtab %}
{% endtabs %}

If the server responds with

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
HTTP/1.1 206 Partial Content
```

{% endcode %}
{% endtab %}
{% endtabs %}

then it supports byte ranges. (If it responds with “HTTP/1.1 200 OK”, then it does not support byte ranges.)

A couple of small notes:

1. If you're storing documents on SharePoint, [caching needs to be enabled](http://msdn.microsoft.com/en-us/library/aa604896.aspx) to enable byte-range requests.
2. If you are serving documents stored in a database served via dynamic web pages, it may not support byte-serving in this specific case. A solution would be to temporarily save the file to a static URL that can then be used for byte serving.

## Open an online PDF document

With a linearized PDF and a webserver that supports byte-range requests, use the following to view the online PDF:

Using [PDFViewCtrl ](http://curl.haxx.se/dlwiz/?type=bin\&os=Win32\&flav=-\&ver=2000/XP):

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
await _PDFViewCtrl.OpenURLAsync("http://example.com/sample.pdf");
```

{% endcode %}
{% endtab %}
{% endtabs %}

And that is it! You will see the document starts to show up shortly after.

### Restrict data usage

By default, the file will be downloaded continuously until the entire file finishes downloading. However, if you are concerned about data usage, it is possible to only download parts of the PDF document that is currently on-screen. Everything that is off-screen is not downloaded to keep minimum data usage.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
HTTPRequestOptions httpRequestOptions = new HTTPRequestOptions();
httpRequestOptions.RestrictDownloadUsage(true);
await _PDFViewCtrl.OpenURLAsync(url);
```

{% endcode %}
{% endtab %}
{% endtabs %}

As more and more data heads to the cloud, it's important that information that is stored remotely can be accessed in a fast, responsive manner. Using linearized PDF documents with PDFNet's OpenURL method is a way to deliver a top-notch remote PDF viewing experience.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/uwp/viewer/view-online-pdfs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
