> 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/portfolios/samples.md).

# Sample to create PDF Portfolio (packages)

Create PDF Portfolios with ease using JavaScript. Learn how to manipulate and extract files within a PDF Portfolio in this comprehensive sample for Apryse's Web SDK. The Apryse Web SDK streamlines sec

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

To create a PDF portfolio containing multiple file types using JavaScript.

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

```js
<html>
  <script src="../lib/core/webviewer-core.min.js"></script>
  <script src="../lib/core/pdf/PDFNet.js"></script>
  <script>
    (async function() {
      Core.setWorkerPath('../lib/core');

      async function AddPackage(doc, file, desc) {
        const files = await PDFNet.NameTree.create(doc.getSDFDoc(), "EmbeddedFiles");
        const fs = await PDFNet.FileSpec.create(doc, file, true);
        var key = new TextEncoder("utf-8").encode(file);
        files.put(key, fs.getSDFObj());
        fs.getSDFObj().putText("Desc", desc);

        var collection = doc.getRoot().findObj("Collection");
        if (!collection) collection = doc.getRoot().putDict("Collection");

        // You could here manipulate any entry in the Collection dictionary.
          // For example, the following line sets the tile mode for initial view mode
        // Please refer to section '2.3.5 Collections' in PDF Reference for details.
        collection.putName("View", "T");
      }
      var doc = await PDFNet.PDFDoc.create();
      await AddPackage(doc, filename, "PDF");
      await AddPackage(doc, imagename, "Image");
    })()
  </script>
</html>
```

{% endcode %}

[PDFNet.NameTree.create](https://sdk.apryse.com/api/web/Core.PDFNet.NameTree.html#.create__anchor) [PDFNet.NameTree.getSDFObj](https://sdk.apryse.com/api/web/Core.PDFNet.NameTree.html#getSDFObj__anchor) [PDFNet.FileSpec.create](https://sdk.apryse.com/api/web/Core.PDFNet.FileSpec.html#.create__anchor) [PDFNet.FileSpec.getSDFObj](https://sdk.apryse.com/api/web/Core.PDFNet.FileSpec.html#getSDFObj__anchor) [PDFNet.PDFDoc.create](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#.create__anchor) [PDFNet.PDFDoc.getRoot](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#getRoot__anchor) [Core.setWorkerPath](https://sdk.apryse.com/api/web/Core.html#.setWorkerPath__anchor)
{% endtab %}

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

```js
<html>
  <script src="../lib/core/CoreControls.js"></script>
  <script src="../lib/core/pdf/PDFNet.js"></script>
  <script>
    (async function() {
      CoreControls.setWorkerPath('../lib/core');

      async function AddPackage(doc, file, desc) {
        const files = await PDFNet.NameTree.create(doc.getSDFDoc(), "EmbeddedFiles");
        const fs = await PDFNet.FileSpec.create(doc, file, true);
        var key = new TextEncoder("utf-8").encode(file);
        files.put(key, fs.getSDFObj());
        fs.getSDFObj().putText("Desc", desc);

        var collection = doc.getRoot().findObj("Collection");
        if (!collection) collection = doc.getRoot().putDict("Collection");

        // You could here manipulate any entry in the Collection dictionary.
          // For example, the following line sets the tile mode for initial view mode
        // Please refer to section '2.3.5 Collections' in PDF Reference for details.
        collection.putName("View", "T");
      }
      var doc = await PDFNet.PDFDoc.create();
      await AddPackage(doc, filename, "PDF");
      await AddPackage(doc, imagename, "Image");
    })()
  </script>
</html>
```

{% endcode %}

[PDFNet.NameTree.create](https://sdk.apryse.com/api/web/Core.PDFNet.NameTree.html#.create__anchor) [PDFNet.NameTree.getSDFObj](https://sdk.apryse.com/api/web/Core.PDFNet.NameTree.html#getSDFObj__anchor) [PDFNet.FileSpec.create](https://sdk.apryse.com/api/web/Core.PDFNet.FileSpec.html#.create__anchor) [PDFNet.FileSpec.getSDFObj](https://sdk.apryse.com/api/web/Core.PDFNet.FileSpec.html#getSDFObj__anchor) [PDFNet.PDFDoc.create](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#.create__anchor) [PDFNet.PDFDoc.getRoot](https://sdk.apryse.com/api/web/Core.PDFNet.PDFDoc.html#getRoot__anchor) [CoreControls.setWorkerPath](https://sdk.apryse.com/api/web/Core.html#.setWorkerPath__anchor)
{% endtab %}
{% endtabs %}


---

# 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/portfolios/samples.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.
