Mayank shrivastav
Mayank shrivastav

Reputation: 1

Convert HTML to PDF in node Js and open in new tab in browser without saving it

I am getting suggestion to use html-pdf npm package but it downloads the converted pdf file and I want to download only when clicked on download pdf button else I just want to open it in new tab or window without downloading. Any suggestions please? Thanks in advance.

Upvotes: 0

Views: 1210

Answers (1)

K J
K J

Reputation: 11940

PDF is not viewable in a clients browser like an image or text.

It is for all intents a bitstream DOCUMENT file, like say a DocX so it needs Binary applications to view it, and some powerhouse browsers include a built in PDF.js EXTENSION/ Foxit/Skia application/pdf PLUGIN.

So just like viewing a DocX or Video you need to download PDF to the device and view in a binary.pdf AEIOU viewport (Ahref/Embed/Iframe/Object/cUrl)

So you cannot just dictate "open a tab" or "open a window" to view PDF until after the download. Opening a window or target a _blank tab is anti-social and usually blocked by virus security. Likewise binary in Iframe will often be blocked. enter image description here

So on a positive note how to offer a PDF (href and iframe are the 2 recommended) one way is to offer a thumbnail of the expected download. Thus you can use pictures to overlay a download <a href="file.Pdf" download> <img src=.... something like this:-

enter image description here

Or HOPE a user is using out of the box view InlineFrames even if their pop-up blocker stops new tabs and new windows.

enter image description here

Or you could use a Page to PDF print method, but it will offer to save the Download or Printout.

enter image description here

Upvotes: 1

Related Questions