> 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/web/get-started/guides/get-file-data-without-viewer.md).

# Get file data without a viewer

Learn how to get file data without a viewer. Retrieve document data from a PDF using Document or PDFDoc objects using JavasScript. Opt for getFileData for easy control and safety over saveMemoryBuffer

A PDF can be loaded into a [Document](https://sdk.apryse.com/api/web/Core.Document.html) or [PDFDoc](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html) object using their respective functions to acquire the document data.

## Getting data from a Document object

To get document data by creating a new `Document` object, the following example shows how to use a `createDocument` to retrieve document data from an external URL.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}

<pre class="language-js" data-line-numbers><code class="lang-js">const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>';
const documentURL = 'Enter Document URL Here';
const extension = 'pdf'; // pass extension to option if there is no file extension in documentURL

// create Core.Document instance
Core.createDocument(documentURL, { l: licenseKey, extension })
  .then(doc => {

    // optionally perform some document processing using read write operations 
    // found under 'Editing Page Content' or 'Page Manipulation'

    doc.getFileData().then(data => {
      const arr = new Uint8Array(data);
      const blob = new Blob([arr], { type: 'application/pdf' });
      // add code for handling Blob here
    });
  })
  .catch(err => { })
</code></pre>

[Core.createDocument](https://sdk.apryse.com/api/web/Core.html#.createDocument__anchor)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}

<pre class="language-js" data-line-numbers><code class="lang-js">const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>';
const documentURL = 'Enter Document URL Here';
const extension = 'pdf'; // pass extension to option if there is no file extension in documentURL

// create CoreControls.Document instance
CoreControls.createDocument(documentURL, { l: licenseKey, extension })
  .then(doc => {

    // optionally perform some document processing using read write operations 
    // found under 'Editing Page Content' or 'Page Manipulation'

    doc.getFileData().then(data => {
      const arr = new Uint8Array(data);
      const blob = new Blob([arr], { type: 'application/pdf' });
      // add code for handling Blob here
    });
  })
  .catch(err => { })
</code></pre>

[CoreControls.createDocument](https://sdk.apryse.com/api/web/Core.html#.createDocument__anchor)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
`Document` objects also have a `getPDFDoc` function for retrieving an associated `PDFDoc` object. However `getFileData` is preferred over `saveMemoryBuffer` in most cases because `getFileData` gives easy control over the output and is safer (it ensure everything is loaded and it take care of locks). The only reason to use `saveMemoryBuffer` over `getFileData`, is if there isn't an easy way of acquiring a `Document` object or if you need other `PDFDoc` features for controlling the download process.
{% endhint %}

## Getting data from a PDFDoc object

{% hint style="warning" %}
Make sure you have [Full API enabled in WebViewer.](/web/what-is-webviewer/full-api.md)
{% endhint %}

Another way of getting document data is by using the [`saveMemoryBuffer`](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#saveMemoryBuffer__anchor) function found on `PDFDoc` objects. An example can be found below

<pre class="language-js" data-line-numbers><code class="lang-js">const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>';

async function main() {
  try {
    const documentURL = 'Enter Document URL Here';
    const pdfDoc = await PDFNet.PDFDoc.createFromURL(documentURL);
    
    pdfDoc.initSecurityHandler();
    pdfDoc.lock();
    
    // optionally perform some document processing using read write operations 
    // found under 'Editing Page Content' or 'Page Manipulation'

    const data = await pdfDoc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_remove_unused);
    const arr = new Uint8Array(data);
    const blob = new Blob([arr], { type: 'application/pdf' });
  } catch(err) {
    console.log(err.stack)
  }
}
PDFNet.runWithCleanup(main, licenseKey);
</code></pre>

After acquiring a `PDFDoc` object, use the [`saveMemoryBuffer`](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#saveMemoryBuffer__anchor) function to retrieve the document data. `saveMemoryBuffer` takes in an enum flag similar to `getFileData` flags. The flags can be found in `PDFNet.SDFDoc.SaveOptions` and their values are:

* `e_remove_unused`
* `e_hex_strings`
* `e_omit_xref`
* `e_linearized`
* `e_compatibility`

There is also an `e_incremental` flag but it's ignored when using `saveMemoryBuffer`. `saveMemoryBuffer` modifies the `PDFDoc` data stored in memory, so it's best practice to acquire a write lock for the document.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/web/get-started/guides/get-file-data-without-viewer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
