jsPDF change page format

巧了我就是萌 提交于 2019-12-12 01:48:31

问题


I have a function to set a footer on a page. But I want to make the code more flexible and add an if statement where I want it to set the footer on a different position when the document is an 'a4' or a3'.

function footer(){
    doc.setFontSize(11);
    doc.text(180,280, 'Seite ' + doc.page);
    doc.page ++;
    }

But I can't find the paramater to change the format after the page has been initiated:

var doc = new jsPDF('p', 'mm', 'a4');

I tried:

doc.format('a3');
doc.setFormat = 'a3';
doc.setPageFormat('a3');

but none works.

Does someone know the paramater to change page format anywhere in the code even after "new jsPDF" initiation? Or does this simply not work?

Thanks in advance!


回答1:


You can set format and orientation on each new page:

doc.addPage('a3', 'portrait');

Orientation is either 'portrait' or 'landscape'

Alternately you can also set the height and widht:

doc.addPage(newWidth, newHeight);

In this case the units will be the same as in your jsPDF instantiation ('mm'):

var doc = new jsPDF('p', 'mm', 'a4');



回答2:


  /* -----------PDF GENERATE--------- */
  @ViewChild('reportContent') reportContent: ElementRef;
  downloadPdf() {
    const doc = new jsPDF('l', 'mm', 'a3');

    const specialElementHandlers = {
      '#editor': function (element, renderer) {
        return true;
      }
    };
    const content = this.reportContent.nativeElement;
    doc.fromHTML(content.innerHTML, 15, 10, {

      'width': 100,
      'elementHandlers': specialElementHandlers
    });
    doc.save('ReminderReport' + '.pdf');
  }


来源:https://stackoverflow.com/questions/41848540/jspdf-change-page-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!