Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!