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

138
Visualizações
cordova-plugin-printer printing raw html instead of rendered html

I am using cordova-plugin-printer for one of my Cordova app. I have installed the plugin, and also able to access android native printing service. The plugin's print function can be called in app using it's function cordova.plugins.printer.print(); as described in the plugin documents here and on it's git repository.

I actually need to print a selected <div> from the HTML, using JavaScript/jQuery.

But the problem I'm facing is that when I am passing html as a var this plugin is printing raw HTML, and not the rendered HTML as desired. Where as, if I directly pass HTML code, as a parameter, it gives the desired result.

My Example Code:

When I call

cordova.plugins.printer.print('<h1>How r u</h1>');//print as desired.

But when I write code like this:

<div id="printable">
<h1>How are you</h1>
</div>

var printable = $("#printable").html();
cordova.plugins.printer.print(printable);//prints raw html

Can anyone help? or correct me what am I doing wrong? seems to be something silly, which I am probably unable to figure out.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to remove line breaks from your html. Try

 var printable = $("#printable").html();
 printable = printable.replace(/(\r\n|\n|\r)/gm, '');
 cordova.plugins.printer.print(printable);
about 4 years ago · Juan Pablo Isaza Relatório
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