使用基于用户输入的jsPDF库生成动态pdf(修复错误)

所以,我实际上有这个function。 用下面的JS。 问题出在提交时,下一页不应反映这些更改,而是反映在生成的PDF中。 目前正在正确生成PDF,但是第二页或第二个视图(PDF中生成的内容显示在当前)不应该是这种情况,此静态页面应保持原样并且只能在生成的PDF。

这实际上是原始问题 – 虽然范围已转换为当前问题提示新问题,但URL可用于示例目的,因为它可能会有所帮助。 将自定义HTML内容插入“已检查”项目的复选框容器

texts = { item1: 'Item Box 1 Content html right here!', item2: 'Now its Item Box 2 html content here !', item3: 'This is the example html of Item box 4!', item4: 'Item box number 5 html content is here!', } $("#container").css('background', '#fff') $('.download-pdf').click(function() { 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() { // add here }); 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'); } }); 

尝试:

  var pdf = new jsPDF('p', 'pt', 'a4'); // moved everything relevant to be called within jsPDF object here pdf.addHTML(document.getElementById('records'), function() { // add here texts = { item1: 'Item Box 1 Content html right here!', item2: 'Now its Item Box 2 html content here !', item3: 'This is the example html of Item box 4!', item4: 'Item box number 5 html content is here!', } 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')]); }); });