【问题标题】:iterating the logic to display on webpage迭代逻辑以显示在网页上
【发布时间】:2017-10-27 04:22:24
【问题描述】:

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

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

请在此处找到 plunker 演示:https://plnkr.co/edit/HvKipjWCYsgujJOv6You?p=preview

在迭代$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
);

【问题讨论】:

标签: javascript html


【解决方案1】:

只需使用<!--ADD_PAGE-->(带有注释角大括号的ADD_PAGE)从您想要新页面的地方

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

Working fiddle

【讨论】:

  • 如何从起始页面显示,使用时从页面中间显示内容 source+= "
    "+value.pageHeader + "
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
相关资源
最近更新 更多