Search code examples
htmlweb-applicationsembed

embed does not open a document in Chrome


My Blazor web application needs to display a pdf document. It works in Firefox, but not in chrome. Here is the code:

<embed src="data:application/pdf;base64,@QuoteModel.Base64EngineeringDrawing" style="overflow:auto;width:800px;height:1000px" />

The document is stored in the variable Base64EngineeringDrawing.

Here is how it looks in Firefox:

enter image description here

But in Chrome it is empty. The inspection shows enter image description here

Replacing embed with iframe does not help.

enter image description here

How can this be fixed?


Solution

  • The correct use of iFrame is along the lines of

    <iframe height="500" width="500" src="http://google.com"></iframe>
    

    Note the separate terminator that is not the one used for <embed />

    When using Iframe with embedded datauri: there can be server system and client browser limitations so first test a file under 10KB and then again ensure a test file is under 1.5MB as those can be common hurdles/blockers.

    For PDFs especially as application format, every browser handling of PDF data is different depending on html construction and user settings. Hence the recommended method is provide an optional image of preview thumbnail with <a href="filename link" for download as inline viewing is down to the client preferences.

    Usually my settings in Edge and other browsers is ask, what to do with incoming PDF

    In Firefox on Windows an iFrame with base64 data should offer options like this

    enter image description here

    Edge may not offer user control, when its set to default PDF viewer and may display the frame instantly

    enter image description here

    If I use Palemoon or Waterfox (Firefox based) the frame is blank as I prefer for most PDF downloads and opens either inline or off line in SumatraPDF (depending on page construction)

    enter image description here

    different constructs may behave differently in recent Firefox as there was a security related change around/after version 97.