This do the trick for me.

$.ajax(
{
   url: "myServlet",
   ...
   complete: function(data) {
        $('#myframe').attr('src','data:application/pdf;base64,'+data);
   }
 }
);

Also, you should encode the ajax ans this way base64_encode($data).

I hope you find this helpful.

Answer from Daniel Perez Malagon on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 70595446 › why-binary-string-data-not-show-as-pdf-in-iframe
Why binary String Data not show as PDF in IFrame?
let frame = document.createElement('iframe'); frame.src = window.URL.createObjectURL(blob); let par = document.getElementById('pdf'); par.appendChild(frame); Now IFrame is empty, It not show the data.Above binary has a table data.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1512272 › displaying-binary-pdf-file-on-a-webpage-using-gene
Displaying Binary PDF file on a webpage using Generic Handler - Microsoft Q&A
January 25, 2024 - You can see from the image above, other information regarding the file displayed at the right of the image, but the pdf file which is suppose to show in the area surrounded by the red line, did not display. ... Hi @Donald Symmons, Your problem seems to be because you are not connected to the database. ... You cannot show the content of pdf on the Literal control no matter how you modify the HTTP handler. As I answered use an iframe instead of the Literal control.
Discussions

How to display a PDF in iframe with ajax after calling a servlet
I can see that I have the data as a binary file: %PDF-1.4 %���� 3 0 obj <>stream x��{PU��^A��e�(�...................... ................... startxref 38448 %%EOF · Sorry but I don't have the code here (at home), but I think that the explanations are fairly clear. I don't know why the PDF cannot be downloaded if I use ajax with iframe ... More on stackoverflow.com
🌐 stackoverflow.com
php - Jquery binary response to display pdf in iframe - Stack Overflow
New to jquery/php i have a script i'd like to improve : I am using TCPDF to generate a pdf that i output via 'F' option locally on my server and sending a simple json response (path/file) to displ... More on stackoverflow.com
🌐 stackoverflow.com
apex - How to display downloaded PDF blob in an iframe? - Salesforce Stack Exchange
Then I want to display the PDF in an iframe so that the user can print from within a custom component. More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
July 22, 2019
display pdf from binary data | OutSystems
hi.. i'm still new in mobile outsystems. i have a pdf file and it store in database table in binary data, i tried to display it into pdf, how i should do · i already tried using file pludgin and show it into pdf viewer pludgin but the pdf file didn't show More on outsystems.com
🌐 outsystems.com
August 18, 2020
🌐
Stack Overflow
stackoverflow.com › questions › 30047785 › inject-binary-pdf-into-iframe
Inject binary PDF into IFrame
Having a business web application ... show a PDF document to the user that the client has as a binary value. In other words, I want to 'stream' the contents of an IFrame from a local variable. Is this possible and how? Here is the scenario: the web application is implemented in Silverlight. Different documents (images, reports, etc) are managed by the application, holding them as byte arrays. To display a PDF file ...
🌐
Stack Overflow
stackoverflow.com › questions › 48302234 › jquery-binary-response-to-display-pdf-in-iframe
php - Jquery binary response to display pdf in iframe - Stack Overflow
The simplest way would be to change the request from POST to GET and set the url to the src attribute of the iframe. ... @Musa Isnt there a dataType :binary or something like that so i could get the pdf as binary in success callback and then ...
🌐
DEV Community
dev.to › asifroyal › displaying-pdf-files-in-an-iframe-a-simple-solution-2anj
Displaying PDF Files in an Iframe: A Simple Solution - DEV Community
December 21, 2022 - function displayPdfFromUrl($url) ... Return PDF file content return $data; } This function takes a URL as an argument and uses cURL to download the content of the PDF file at that URL....
🌐
OutSystems
outsystems.com › forums › discussion › 63823 › display-pdf-from-binary-data
display pdf from binary data | OutSystems
August 18, 2020 - hi.. i'm still new in mobile outsystems. i have a pdf file and it store in database table in binary data, i tried to display it into pdf, how i should do · i already tried using file pludgin and show it into pdf viewer pludgin but the pdf file didn't show
Find elsewhere
🌐
Reddit
reddit.com › r/learnprogramming › how can i preview a pdf binary in a browser? expressjs, javascript
r/learnprogramming on Reddit: How can I preview a pdf binary in a browser? Expressjs, JavaScript
July 8, 2022 -

I've been stuck on this for awhile. Long story short, I'm trying to have my web application preview a pdf within the web browser.

My front-end uses a script to send a GET request to retrieve a pdf stored on my backend. My backend successfully sends the pdf data via Expressjs. The front-end receives the pdf binary then stores it within a variable.

From here I have no idea how to render the binary data into a pdf that can be displayed within an html canvas. I was hoping someone might be able to give me a few ideas.

// FILE: app.js (back-end)
const express = require('express');
const app = express();
var fs = require('fs');
var path = require('path');

app.use(express.static('./methods-public'));

app.get('/api/pdf', (req, res) => {
  absolutePath = path.resolve(__dirname, 'dog.pdf');
  res.contentType('application/pdf');
  res.sendFile(absolutePath);
});

app.listen(5000, () => {
  console.log('Server is listening on port 5000....');
});

-

<!-- FILE: index.html (front-end) -->
<!DOCTYPE html>
<html lang="en">
  
  <head>
    <meta charset="UTF-8" />
  </head>

  <body>

    <div class="result"></div>

     <!-- Axios script -->
    <script
      src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"
      integrity="sha512-bZS47S7sPOxkjU/4Bt0zrhEtWx0y0CRkhEp8IckzK+ltifIIE9EMIMTuT/mEzoIMewUINruDBIR/jJnbguonqQ=="
      crossorigin="anonymous"
    ></script>

     <!-- PDF logic -->
    <script>
      const result = document.querySelector('.result');

      const fetchPDF = async () => {
        try {
          const { data } = await axios.get('/api/pdf');
          result.innerHTML = '<h3>' + data + '</h3>';
        } catch (error) {
          result.innerHTML = `<div class="alert alert-danger">Can't Fetch PDF</div>`;
        }
      };

      fetchPDF();
    </script>

  </body>
</html>
🌐
Salesforce
help.salesforce.com › HTViewSolution
Salesforce Help
September 2, 2015 - Loading · ×Sorry to interrupt · Refresh
🌐
FlipHTML5
fliphtml5.com › home page › pdf tips & tools › pdf embedding › the best way to display pdf in iframe
The Best Way to Display PDF in iFrame - FlipHTML5
June 5, 2023 - After you have customized your flipbook, FlipHTML5 provides you with an embed code that you can use to display your PDF as a flipbook in an interactive iframe on your website. Locate the embed code provided by FlipHTML5 and copy it. Then, navigate to the webpage where you want to display the flipbook and paste the embed code into the appropriate section of your HTML code.
🌐
Nutrient
nutrient.io › blog › sdk › how to embed a pdf viewer in your website
How to embed a PDF viewer in a website: Six methods (2026 guide)
March 23, 2026 - Need to display a PDF inside a webpage? This guide covers six methods for embedding PDFs in HTML: pure HTML tags (embed, iframe, object, and a), plus an advanced, fully customizable viewer built with Nutrient Web SDK.
🌐
Stack Overflow
stackoverflow.com › questions › 65533934 › showing-binary-pdf-in-browser-javascript
express - Showing binary PDF in browser Javascript - Stack Overflow
When I have the response, I just convert it to blob and set the src attribute of iframe element with the base64 encoding of the blob · const reader = new FileReader(); reader.onload = () => { const b64 = reader.result.replace(/^data:.+;base64,/, ""); $('#view').attr('src','data:application/pdf;base64,'+ b64); }; reader.readAsDataURL(new Blob([resp.data], { type: "application/pdf" }));