Javascript 迭代逻辑以显示在网页上

Javascript 迭代逻辑以显示在网页上,javascript,html,Javascript,Html,我有一个对象列表,在获取对象的每个元素时,我希望将每个元素导出到PDF中的各个页面 我通过迭代列表对象(例如,$scope.employees)来获取数据。当前,当用户单击“导出”按钮时,数据将导出为PDF格式。我的要求是迭代时的每个对象都应该存储在PDF的各个页面中。例如,pageHeader为“This is Show in page1”的对象应显示在page1中,“This is Show in page2”的对象在打开时应显示在PDF的page2中等。 如对此有任何建议,将不胜感激 请在

我有一个对象列表,在获取对象的每个元素时,我希望将每个元素导出到PDF中的各个页面

我通过迭代列表对象(例如,
$scope.employees
)来获取数据。当前,当用户单击“导出”按钮时,数据将导出为PDF格式。我的要求是迭代时的每个对象都应该存储在PDF的各个页面中。例如,pageHeader为“This is Show in page1”的对象应显示在page1中,“This is Show in page2”的对象在打开时应显示在PDF的page2中等。
如对此有任何建议,将不胜感激

请在此处找到plunker演示:

在迭代
$scope.employees
时,是否需要使用
pageSplit:true
选项,是否有任何输入

js代码:

$scope.export = function(){
alert("in pdf export");
var pdf = new jsPDF('landscape');
var width1 = pdf.internal.pageSize.width;
var height = pdf.internal.pageSize.height;

var source = "";
$scope.employees.forEach(function(value){
    source+= value.pageHeader + "\n" +"\n";
})
specialElementHandlers = {
    // element with id of "bypass" - jQuery style selector
    '#bypassme': function (element, renderer) {
        // true = "handled elsewhere, bypass text extraction"
        return true
    }
};
margins = {
    top: 80,
    bottom: 60,
    left: 10,
    width: '100%'
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
    source, // HTML string or DOM elem ref.
    margins.left, // x coord
    margins.top, { // y coord
        'width': width1, // max width of content on PDF
        'elementHandlers': specialElementHandlers
    },
    function (dispose) {
        // dispose: object with X, Y of the last line add to the PDF
        //          this allow the insertion of new lines after html
        pdf.save('test.pdf');
    },
    margins
);
只需使用
(添加带有注释中的角括号的页面)从您想要的新页面开始

source+= "<div>"+value.pageHeader + "</div><!--ADD_PAGE-->";
source+=“”+value.pageHeader+“”;

只需在需要新页面的地方使用
(添加带注释的角括号的页面),例如

source+= "<div>"+value.pageHeader + "</div><!--ADD_PAGE-->";
source+=“”+value.pageHeader+“”;

此问题是否回答了此问题:?此问题是否回答了此问题:?如何从起始页显示,使用source+=''value.pageHeader+''时,内容从页面中间显示;而有些行尾的单词并没有显示在PDF上,这可能是页面布局问题。请给出建议。@jitenderth这是因为您使用的是
margins={top:80,bottom:60,left:10,width:'100%}
将此更改为
margins={top:20,bottom:10,left:10,width:'100%}
我在将内容导出为PDF时遇到了另一个问题,我在这里提出了这个问题。如果可能的话,任何输入都会有帮助。@jitenderHow要从起始页显示,当使用source+=''value.pageHeader+''时,内容将从页面中间显示;而有些行尾的单词并没有显示在PDF上,这可能是页面布局问题。请给出建议。@jitenderth这是因为您使用的是
margins={top:80,bottom:60,left:10,width:'100%}
将此更改为
margins={top:20,bottom:10,left:10,width:'100%}
我在将内容导出为PDF时遇到了另一个问题,我在这里提出了这个问题。任何可能的输入都会有帮助。@jitender