Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据用户输入使用jsPDF库生成动态pdf(修复错误)_Javascript_Jquery_Jspdf - Fatal编程技术网

Javascript 根据用户输入使用jsPDF库生成动态pdf(修复错误)

Javascript 根据用户输入使用jsPDF库生成动态pdf(修复错误),javascript,jquery,jspdf,Javascript,Jquery,Jspdf,所以,我实际上有这个功能。用下面的JS。问题在于提交时,下一页不应反映这些更改,而应仅反映在生成的PDF中。目前,PDF正在正确生成,但第二页或第二视图(PDF中生成的内容显示在当前页面上)不应是这种情况,该静态页面应保持原样,仅在生成的PDF中可以查看反映的更改 这里实际上是原始问题-虽然范围已转换为当前问题暗示了新问题,但URL可能有助于示例目的 文本={ item1:'项目框1内容html就在这里!', item2:'现在它的项目框2htmlcontent here!', 项目3:'这是项

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

这里实际上是原始问题-虽然范围已转换为当前问题暗示了新问题,但URL可能有助于示例目的

文本={
item1:'项目框1内容html就在这里!',
item2:'现在它的项目框2htmlcontent here!',
项目3:'这是项目框4的示例html!',
item4:'项目框编号5html内容在这里!',
}
$(“#容器”).css('background','#fff'))
$('.download pdf')。单击(函数(){
notChecked=$(“输入[类型=复选框]:未(:选中)”).parent();
隐藏();
yesChecked=$(“输入[类型=复选框]:选中”).parent();
$.each(yesChecked,函数(索引,el){
$(el.show().html(文本[$(el.attr('id')));
});
var pdf=新的jsPDF('p','pt','a4');
pdf.addHTML(document.getElementById('records'),function(){
//加在这里
}); 
var文件='test';
如果(单据类型!==“未定义”){
doc.save(文件+'.pdf');
}else if(pdf的类型!=“未定义”){
setTimeout(函数(){
pdf.save(file+'.pdf');
//$(“#item4”).hide();
}, 2000);
}否则{
警报(“错误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 <strong>html</strong> right here!',
        item2: 'Now its Item Box 2 <strong>html</strong> content here !',
        item3: 'This is the example <strong>html</strong> of Item box 4!',
        item4: 'Item box number 5 <strong>html</strong> 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')]);
        });

    }); 
var pdf=newjspdf('p','pt','a4');//将要在jsPDF对象中调用的所有相关内容移到此处
pdf.addHTML(document.getElementById('records'),function(){
//加在这里
文本={
item1:'项目框1内容html就在这里!',
item2:'现在它的项目框2htmlcontent here!',
项目3:'这是项目框4的示例html!',
item4:'项目框编号5html内容在这里!',
}
notChecked=$(“输入[类型=复选框]:未(:选中)”).parent();
隐藏();
yesChecked=$(“输入[类型=复选框]:选中”).parent();
$.each(yesChecked,函数(索引,el){
$(el.show().html(文本[$(el.attr('id')));
});
}); 

不确定你想要什么,你能简单地描述一下并包含剪贴的内容吗?嘿,Michael-所以我只需要在PDF中生成触发下载的选项。(为了实际看到这种情况发生,您必须将上述代码放入MAMP或服务器中)。基本上我们在上一个问题上做了什么-除了它没有出现在页面上,或者在第二个视图中。只有它显示在PDF中。实际上,在我们的上一个问题中,它在PDF中生成的很好,但它也显示在页面上。它不应该显示在页面上,只显示在那个PDF文件中。正如您在上面的addhere//注释中所看到的。这就是为什么我尝试移动jsPDF对象中的所有内容。因为所有这些功能应该只出现在生成的pdf中。啊,所以你希望第二个页面是pdf而不是页面,对吗?如果是,你想在提交后触发下载?
 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 <strong>html</strong> right here!',
        item2: 'Now its Item Box 2 <strong>html</strong> content here !',
        item3: 'This is the example <strong>html</strong> of Item box 4!',
        item4: 'Item box number 5 <strong>html</strong> 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')]);
        });

    });