# How to display a PDF file in a new tab

**URL:** <https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573>\
**Category:** General\
**Created:** [19 March 2024 18:33 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573 "2024-03-19T18:33:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [19 March 2024 18:33 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/1 "2024-03-19T18:33:13Z")

</div>

I made the HTML file display (read as utf 8) in a new tab as described by dear Steve-Mcl:  
[https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419](https://flows.nodered.org/flow/db68bd4934cf46f39e6e453a348bc419)

But the PDF file can only be downloaded in a new tab (read as buffer).  
And how do I make it display too?  
Please help me with some advice.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 March 2024 21:09 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/2 "2024-03-19T21:09:22Z")

</div>

You most likely need to set the content-type header to `application/pdf`.

> **[Content-Type - HTTP | MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type)**
>
> The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending).

Then, it will be up to the browser whether it renders or downloads it.

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [20 March 2024 08:14 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/3 "2024-03-20T08:14:46Z")

</div>

**TotallyInformation** , Thanks for the idea !

Flow from Steve-Mcl

 ![64486977-5b14e200-d22c-11e9-86b4-b06d9e7cf22f1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/004276bfa4dabd2989047ff237c6ae3e0b894c26.png)

A message is coming from the node "[get] /files/:fn:"

> {  
> "\_msgid": "ff8bc8b8.9f8808",  
> "payload": {},  
> "req": {  
> "\_readableState": {  
> "objectMode": false,  
> "highWaterMark": 16384,  
> "buffer": {  
> "head": null,  
> "tail": null,  
> "length": 0  
> },  
> "length": 0,  
> "pipes": ,  
> "flowing": null,  
> "ended": true,  
> "endEmitted": false,  
> "reading": false,  
> "constructed": true,  
> "sync": true,  
> "needReadable": false,  
> "emittedReadable": false,  
> "readableListening": false,  
> "resumeScheduled": false,  
> "errorEmitted": false,  
> "emitClose": true,  
> "autoDestroy": true,  
> "destroyed": false,  
> "errored": null,  
> "closed": false,  
> "closeEmitted": false,  
> "defaultEncoding": "utf8",  
> "awaitDrainWriters": null,  
> "multiAwaitDrain": false,  
> "readingMore": true,  
> "dataEmitted": false,  
> "decoder": null,  
> "encoding": null  
> },  
> "\_events": {},  
> "\_eventsCount": 1,  
> "socket": "[internal]",  
> "httpVersionMajor": 1,  
> "httpVersionMinor": 1,  
> "httpVersion": "1.1",  
> "complete": true,  
> "rawHeaders": [  
> "Host",  
> "192.168.11.123:1882",  
> "Connection",  
> "keep-alive",  
> "Upgrade-Insecure-Requests",  
> "1",  
> "User-Agent",  
> "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",  
> "Accept",  
> **"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,_/_;q=0.8,application/signed-exchange;v=b3;q=0.9"** ,  
> "Referer",  
> "[http://192.168.11.123:1882/ui/](http://192.168.11.123:1882/ui/)",  
> "Accept-Encoding",  
> "gzip, deflate",  
> "Accept-Language",  
> "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",  
> "Cookie",  
> "\_authorized=admin; sysmode=router; FKUYKTUMUIWNE=SIHGUZCDNEEBCTHC"  
> ],  
> "rawTrailers": ,  
> "aborted": false,  
> "upgrade": false,  
> "url": "/files/Test.pdf",  
> "method": "GET",  
> "statusCode": null,  
> "statusMessage": null,  
> "client": "[internal]",  
> "\_consuming": false,  
> "\_dumped": false,  
> "baseUrl": "",  
> "originalUrl": "/files/Test.pdf",  
> "\_parsedUrl": {  
> "protocol": null,  
> "slashes": null,  
> "auth": null,  
> "host": null,  
> "port": null,  
> "hostname": null,  
> "hash": null,  
> "search": null,  
> "query": null,  
> "pathname": "/files/Test.pdf",  
> "path": "/files/Test.pdf",  
> "href": "/files/Test.pdf",  
> "\_raw": "/files/Test.pdf"  
> },  
> "params": {  
> "fn": "Test.pdf"  
> },  
> "query": {},  
> "res": "[internal]",  
> "body": {},  
> "\_parsedOriginalUrl": {  
> "protocol": null,  
> "slashes": null,  
> "auth": null,  
> "host": null,  
> "port": null,  
> "hostname": null,  
> "hash": null,  
> "search": null,  
> "query": null,  
> "pathname": "/files/Test.pdf",  
> "path": "/files/Test.pdf",  
> "href": "/files/Test.pdf",  
> "\_raw": "/files/Test.pdf"  
> },  
> "route": {  
> "path": "/files/:fn",  
> "stack": [  
> {  
> "name": "cookieParser",  
> "keys": ,  
> "regexp": {  
> "fast\_star": false,  
> "fast\_slash": false  
> },  
> "method": "get"  
> },  
> {  
> "name": "httpMiddleware",  
> "keys": ,  
> "regexp": {  
> "fast\_star": false,  
> "fast\_slash": false  
> },  
> "method": "get"  
> },  
> {  
> "name": "corsHandler",  
> "keys": ,  
> "regexp": {  
> "fast\_star": false,  
> "fast\_slash": false  
> },  
> "method": "get"  
> },  
> {  
> "name": "metricsHandler",  
> "keys": ,  
> "regexp": {  
> "fast\_star": false,  
> "fast\_slash": false  
> },  
> "method": "get"  
> },  
> {  
> "name": "",  
> "keys": ,  
> "regexp": {  
> "fast\_star": false,  
> "fast\_slash": false  
> },  
> "method": "get"  
> },  
> {  
> "name": "",  
> "keys": ,  
> "regexp": {  
> "fast\_star": false,  
> "fast\_slash": false  
> },  
> "method": "get"  
> }  
> ],  
> "methods": {  
> "get": true  
> }  
> },  
> "cookies": {  
> "\_authorized": "admin",  
> "sysmode": "router",  
> "FKUYKTUMUIWNE": "SIHGUZCDNEEBCTHC"  
> },  
> "signedCookies": {}  
> },  
> "res": {}  
> }

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [20 March 2024 08:28 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/4 "2024-03-20T08:28:55Z")

</div>

A message is coming from the node.  
I replaced it:

> "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,_/_;q=0.8,application/signed-exchange;v=b3;q=0.9"

with this:

> **application/pdf** ,text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,_/_;q=0.8,application/signed-exchange;v=b3;q=0.9  
> и далее это уходит на узел "http".

But nothing has changed.

How else can I insert Content-Type = "application/pdf" ?

Inserting " **application/force-download**" also did not result in a download request.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 March 2024 10:57 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/5 "2024-03-20T10:57:02Z")

</div>

`application/pdf` in this context is the response header.  
Doubleclick the http-response node and set the content-type header to application/pdf.

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [20 March 2024 11:24 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/6 "2024-03-20T11:24:37Z")

</div>

> [@bakman2](#):
>
> Doubleclick the http-response node and set the content-type header to application/pdf.

Thank you very much!  
It is also possible programmatically from the function node:

> msg.headers = {'Content-Type':'application/pdf'};

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 April 2024 11:24 UTC](https://discourse.nodered.org/t/how-to-display-a-pdf-file-in-a-new-tab/86573/7 "2024-04-03T11:24:37Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
