POST html to PDF

by Luis Valle

HTML

<div id="dvContents">
  <div style="background-color:yellow;border:1px solid orange;">
    <label>Hello There test</label>
  </div>
</div>
<div>
  <button id="btnConvert">
    Convert to PDF
  </button>
</div>

JavaScript

(function () {
	$('#btnConvert').on('click', function () {
  	$('#btnConvert').attr('disabled', 'disabled');
  
  	postHTMLAJAX()
    .then(function () {
    	$('#btnConvert').removeAttr('disabled');
    });
  });
})();

var d;
function postHTMLAJAX() {
	d = $.Deferred();
	$('body').append("<form method='POST' action='https://www.evicore.net/webservices/evicoreservice.asmx/postHTMLtoPDFJS' style='position:fixed;top:-3333333333px;'" +
                   " id='tempForm' onsubmit='resolvePromise();'><input" +
                   " type='hidden' name='inHTML' value='" + $('#dvContents').html().replace(/\</g, '⌐').replace(/\>/g, '¬') + "' /><input type='hidden'" +
                   " name='properties' value='" + JSON.stringify({ fileformat: 'doc' }) + "' /><input" +
                   " type='hidden' name='FileNamex' value='testPDFfile.doc' /><input" +
                   " type='submit' value='Submit' style='opacity:0;' class='HiddenBtn' /></form>");
  $('#tempForm').submit(); //.remove()
  
  return d.promise();
}

function resolvePromise() {
	d.resolve(true);
  $('#tempForm').remove();
  alert('resovled');
}

function postHTMLAJAX2() {
	$.ajax({
        type: "POST",
        url: "https://www.evicore.net/webservices/evicoreservice.asmx/postHTMLtoPDFJS",
        data: JSON.stringify({ inHTML: $('#dvContents').html(), FileNamex: 'testPDFFile.pdf', properties: '' }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function () {
        	console.log('done good');
        },
        error: function (ahxj, err) {
        	console.log(err);
        }
    });
}