# Async Load PDF Through Stream

**URL:** <https://pdfjs.community/t/async-load-pdf-through-stream/2095>\
**Category:** Technical Support\
**Created:** [October 5, 2022, 11:19pm UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095 "2022-10-05T23:19:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![skyler.ochsenbein](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@skyler.ochsenbein](https://pdfjs.community/u/skyler.ochsenbein)\
**Post date:** [October 5, 2022, 11:19pm UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095/1 "2022-10-05T23:19:21Z")

</div>

**Which product are you using?**  
PDF.js Express Viewer

**PDF.js Express Version**  
8.7.0

**Detailed description of issue**  
I am putting together a small proof of concept to test out the PDF.js Express Viewer library. I’ve been able to load up a PDF from the React/Vite project’s `public` directory just fine, and I have found topics where people have loaded PDFs from public URLs and pre-signed AWS S3 URLs.

Is it possible to asynchronously load PDFs through a stream? All PDFs are stored on a NAS server. I’d like to make an API request to our server that would then serve back the file stream.

The alternative solution in my mind would be to create public access to the NAS server. Though it’d be through a reverse proxy, it’s still not ideal, for obvious security reasons. It’d also mean having to configure and maintain an external solution outside of the main project’s codebase.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [October 5, 2022, 11:19pm UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095/3 "2022-10-05T23:19:26Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:
- [Manually download and integrate PDF.js Express Viewer - Integrate into your application](https://pdfjs.express/documentation/get-started-viewer/manually#integrate-into-your-application)
- [Integrating PDF.js Express Viewer into a Vue.js project - Sample overview](https://pdfjs.express/documentation/get-started-viewer/vue#sample-overview)
- [Integrating PDF.js Express Plus with Vue.js - Sample overview](https://pdfjs.express/documentation/get-started/vue#sample-overview)

APIs:
- [PDF.js Express Utilities](https://pdfjs.express/api/utils/index.html#__anchor)
- [Core.Annotations.Forms.FieldManager - setPrintHandler()](https://pdfjs.express/api/Core.Annotations.Forms.FieldManager.html#setPrintHandler__anchor)
- [ExpressUtils(optionsopt) - # async merge() → {Promise.}](https://pdfjs.express/api/utils/ExpressUtils.html#merge__anchor)

Forums:
- [Any way to prevent WebViewer from doing HEAD request?](https://pdfjs.community/t/any-way-to-prevent-webviewer-from-doing-head-request/1147/1)
- [Hyperlinks not being detected in pdf.js viewer](https://pdfjs.community/t/hyperlinks-not-being-detected-in-pdf-js-viewer/1925/1)
- [PDF.js Express access to AWS S3 object with pre-signed URL](https://pdfjs.community/t/pdf-js-express-access-to-aws-s3-object-with-pre-signed-url/1657/1)

  
  

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [October 6, 2022, 6:03pm UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095/4 "2022-10-06T18:03:45Z")

</div>

Hi [skyler.ochsenbein](https://pdfjs.community/u/skyler.ochsenbein),

Can you share a sample code how you are loading the PDF through a stream?  
Here’s our documentation regarding loading PDF through different domain:

> **[What is PDF.js Express? | Documentation](https://pdfjs.express/documentation/learn-more/inside-express-viewer.8#load-pdf.js-express-viewer-from-another-domain)**

Here is a forum guide that may help you answer some of your questions:

> [@Using the HttpPartRetriever](https://pdfjs.community/t/using-the-httppartretriever/887):
>
> Hey Guys, Trying to make use of the low level apis in PDF JS Express 7.3.5. We operate a custom DRM server (similar to XOD) and would like to stream and decrypt ranges of PDFs documents. I’ve had a go at using the HttpPartRetriever with the following code: CoreControls.getDefaultBackendType().then(async (backendType: any) =\> { const retriever = await PartRetrievers.getPartRetriever(PartRetrievers.Types.HttpPartRetriever, "http://ourserver.com/3ba24f65b430.pdf", { decrypt: (…

Best Regards,  
Kevin Kim  
Web Development Support Engineer  
PDFTron Systems, Inc.

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![skyler.ochsenbein](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@skyler.ochsenbein](https://pdfjs.community/u/skyler.ochsenbein)\
**Post date:** [October 7, 2022, 7:14pm UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095/5 "2022-10-07T19:14:32Z")

</div>

Hey Kevin,

I haven’t tried a solution yet, as my question is how to go about doing that. I’d like to be able to load the PDFs through a Node.js Express backend and serve the file back up to the React frontend. I’m trying to avoid having to statically host the files with a public URL.

Thanks,

Skyler

---

<div class="post-metadata">

**Author:** ![kkim](https://avatars.discourse-cdn.com/v4/letter/k/3ab097/32.png) [@kkim](https://pdfjs.community/u/kkim)\
**Post date:** [October 7, 2022, 10:03pm UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095/6 "2022-10-07T22:03:05Z")

</div>

Hi [skyler.ochsenbein](https://pdfjs.community/u/skyler.ochsenbein),

I am not sure how you would be able to achieve this, as you would still need to make a fetch request to the location where you PDFs are stored (NAS server).  
[https://pdfjs.express/api/utils/tutorial-Using%20in%20node.html](https://pdfjs.express/api/utils/tutorial-Using%20in%20node.html)

Like you mentioned, the alternative would be to create the NAS public.

If the NAS server is a subdomain, then you could potentially make a request but there are some things to be mindful of, like CORS issue within an iframe:

> **[PDF.js Express Viewer Download & Integration | Documentation](https://pdfjs.express/documentation/get-started-viewer/add-license-key)**

[Loading PDF.js Express from a CDN or another origin | Documentation](https://pdfjs.express/documentation/learn-more/cors#1))-copy-assets-to-cdn

Best Regards,  
Kevin Kim  
Web Development Support Engineer  
PDFTron Systems, Inc.

Share how you are using PDF.js Express in your organization you could win a **$500 Amazon gift card. All participants will receive 6 months of PDF.js Express+ for free**. Learn more [here](https://utm.guru/ueQNw)

---

<div class="post-metadata">

**Author:** ![skyler.ochsenbein](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@skyler.ochsenbein](https://pdfjs.community/u/skyler.ochsenbein)\
**Post date:** [October 14, 2022, 5:04am UTC](https://pdfjs.community/t/async-load-pdf-through-stream/2095/7 "2022-10-14T05:04:47Z")

</div>

It looks like there’s a lot simpler way I can do this using `express.static`. The server will have access to the NAS server, I can just create a static path and hide the URL behind a private route. Then for additional security I can generated uuid’s in the database mapped to each PDF so the frontend just passes that into to my API and it can find the correct file.

Example of using `express.static`, for anyone else that may have this concern. Add the following to the server index:

```javascript
app.use('/pdf', express.static(__dirname + '/pathToPDF'));

```
