Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
Why binary String Data not show as PDF in IFrame?

Here is what I tried

I get some binary string sending a GET request to some API

   let BinaryData = await Operations._sendRequest(baseURL + '/getBinaryString/', 'GET');

above Request give to me like this string

  "%PDF-1.4
%����
4 0 obj
<</Length 5076/Filter/FlateDecode>>stream
x���Kw�F���� Xxa�c� ���\��g��.��E{ ,���-�e����}
................................................................
startxref
5701
%%EOF
"

Firstly I try to encode this string

 const encoder = new TextEncoder()
 let encodeBinaryData = encoder.encode(BinaryData)

Then I convert it to blob

 let blob = new Blob([encodeBinaryData],{type: "application/pdf"});

Finaly I am going to show this data 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. I can sent the following responceType to API, But I dont want to use that way

 responceType:"blob" 

if I send the responceType as blob I can get tha data as BLOB and send it to iframe and show as PDF I can see my all data there.

But I want to show the PDF data using above code. I tested if I can show the string in iframe

let str = "Hello World"
let encodeBinaryData = encoder.encode(str)
let blob = new Blob([encodeBinaryData],{type: "text/plain"});

Then I can see correct string there, EX: Hello world

But If I use {type: "application/pdf"} I cant see anything

how Can I fix this problem? (I am using pure HTML)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda