So, currently I have a static page with HTML / form checkboxes. Only the checkboxes that are selected generate into the JS pdf; the content is swapped from 'checkbox' to my HTML via the parent div. The problem is after the 'Generate PDF' button is hit. The current page, then shows the changes made and what resolves into the PDF, only the PDF should generate via this code. The current page should not change at all. Any thoughts? Basically after 'Download PDF' is hit, the PDF downloads via the user input that is described above and written in JS below, however; the page itself should not reflect these changes. Currently the PDF generates accurately, but the page also changes to what the PDF is.
$(document).ready(function() {
texts = {
item1: 'Item Box 1 Content <strong>html</strong> right here! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
item2: 'Now its Item Box 2 <strong>html</strong> content here ! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
item3: 'This is the example <strong>html</strong> of Item box 4! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
item4: 'Item box number 5 <strong>html</strong> content is here! Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
}
$("#container").css('background', '#fff')
$('.download-pdf').click(function() {
// this should trigger the below to generate in the PDF,
// not display it on page > then generate to pdf. Just pdf!
notChecked = $("input[type=checkbox]:not(:checked)").parent();
notChecked.hide();
yesChecked = $("input[type=checkbox]:checked").parent();
$.each(yesChecked, function( index, el ) {
$(el).show().html(texts[$(el).attr('id')]);
});
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML(document.getElementById('records'), function() {
setTimeout(function(){
location.reload();
},3000);
});
var file = 'test';
if (typeof doc !== 'undefined') {
doc.save(file + '.pdf');
} else if (typeof pdf !== 'undefined') {
setTimeout(function() {
pdf.save(file + '.pdf');
// $("#item4").hide();
}, 2000);
} else {
alert('Error 0xE001BADF');
}
});
$('.checkmate').on('click', function() {
if ($(this).is(':checked'))
$(this).parent('div').css({"color":"white","background":"green"});
else
$(this).parent('div').css('background-color', '');
});
});
HERE IS A SAMPLE JSFIDDLE DEMO.. to help illustrate (however the PDF generation functionality requires live server) So, if you can imagine maintaining the functioning 'Static Page checkbox conditions > PDF' and just not having the static page itself, change that the user is on. That is the goal.