4

After downloading a pdf as a base64 string with a request, I want to open a new tab and display the pdf with the "fit screen" option enabled.

The iframe code, where pdf is the base64 string:

var win = window.open('', '', '');
win.document.write(`
  <iframe src="data:application/pdf;base64,${pdf}" width=100% height=100%></iframe>
`);

This answers how to adjust settings with a filename as src:

<iframe src="filename.pdf#view=FitH"></iframe>

Unfortunately, src="base64string#view=FitH" doesn't work. Any way to still accomplish this?

Community
  • 1
  • 1
Laoujin
  • 9,962
  • 7
  • 42
  • 69
  • What is purpose of using ` – guest271314 Jan 08 '17 at 19:42
  • In the actual code, it also writes some tags and css to the window [to avoid double scrollbars](http://stackoverflow.com/questions/2758732/how-to-get-rid-of-the-double-scroll-bar-problem-when-using-an-iframe) – Laoujin Jan 08 '17 at 19:44
  • You can substitute `Blob URL` for `data URI` to append fragment identifier to URL. Not certain how to check if `#view=FitH` is being applied, though the fragment identifier will be concatenated at resulting `Blob URL`. – guest271314 Jan 08 '17 at 19:45
  • @Laoujin Did you find a solution for this? – Emilios1995 Jan 31 '18 at 18:32
  • Unfortunately not. – Laoujin Feb 01 '18 at 09:07
  • i found a solution here: https://stackoverflow.com/questions/35371246/data-uri-hash-parameters-hide-pdf-toolbar-for-data-uri – Jonathan Armando Rojas Lopez Apr 06 '18 at 14:24
  • @Jonathan Armando Rojas Lopez thanks for the solution, I got it working, but not with the `#view=fitH` (all the other params from that answer seems to be working though). Was there something you had to do specifically to view=fitH ? – SeriousLee Sep 29 '21 at 07:04

0 Answers0