Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
jquery full version
<script src="" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 500px;
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
#banner-message.alt button {
background: #fff;
color: #000;
function printHtmlToPdf(html) {
var endpoint = '';
var apikey = 'YOUR-API-KEY'; //replace this with your own from
var payload = {
"html": html,
"inlinePdf": false
url: endpoint,
method: "POST",
dataType: "json",
crossDomain: true,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(payload),
cache: false,
beforeSend: function (xhr) {
/* Authorization header */
xhr.setRequestHeader("Authorization", apikey);
success: function (data) {
console.log(data.pdf); //this is the url to the pdf, do something with it
document.getElementById('my_iframe').src = data.pdf;
error: function (jqXHR, textStatus, errorThrown) {
<div id="banner-message">
<p>Replace apikey variable with your own API key from <a href="" target="_blank"></a>.
See full documentation <a href="">here</a>.</p>
<button>Print to PDF</button>
<iframe id="my_iframe" style="display:none;"></iframe>
// find elements
var banner = $("#banner-message")
var button = $("button")
// handle click and add class
button.on("click", function () {
var htmlToPrint = '<p>Hello World</p>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.