I'm trying to open a base64 PDF file in a new tab by using iframe. While opening that PDF in new tab file name is showing as data: attached my screenshot below. How can I change or set the file name?.
Note: I don't want to download the PDF I need to open in a new tab. Thanks in advance
My Code
const pdfWindow = window.open('');
pdfWindow.document.write(
"<iframe width='100%' height='100%' src='data:application/pdf;base64, " +
encodeURI(base64PDF) +
"'></iframe>",
);
I'm trying to open a base64 PDF file in a new tab by using iframe. While opening that PDF in new tab file name is showing as data: attached my screenshot below. How can I change or set the file name?.
Note: I don't want to download the PDF I need to open in a new tab. Thanks in advance
My Code
const pdfWindow = window.open('');
pdfWindow.document.write(
"<iframe width='100%' height='100%' src='data:application/pdf;base64, " +
encodeURI(base64PDF) +
"'></iframe>",
);
Share
Improve this question
asked Jun 8, 2020 at 9:27
PravinPravin
4412 gold badges9 silver badges26 bronze badges
1
-
do you mean the result of
<title>
tags in HTML pages? – CanUver Commented Jun 8, 2020 at 10:39
3 Answers
Reset to default 3Maybe this way you can use. There may have been a mistake in the arrangements.
let file = 'data:application/pdf;base64'
let prntWin = window.open();
prntWin.document.write("<html><head><title>your title in here</title></head><body>"
+ '<iframe width="100%" height="100%" src="'+ file + '" '
+ 'type="application/pdf" ></body></html>');
prntWin.document.close();
There is a way to show the filename you want, but it needs to save the base64 to LocalFileSystem.
Then the iframe load this file in LocalFileSystem.
And it needs user to grant permission once to the browser.
It works on Chrome. You can refer to below demo:
https://pdf-filename.glitch.me/
Souce:
https://glitch./edit/#!/pdf-filename?path=index.html%3A1%3A0
The download button fail to work...
Edit:
If you would like to use pdf.js, you can refer to:
https://daniel4wong-pdfjs-demo.glitch.me/
The title that you are refering to is in the metadata of the PDF document itself. You will need to edit the title in the document.
You can use an online editor (like https://pdfcandy./edit-pdf-meta.html) or any suitable PDF application.
If you are generating your PDF's on the backend you need to set the proper metadata over there.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744773501a4592906.html
评论列表(0条)