2017-03-21 1 views

Antwort

0

Hye, jedes Mal hinzuzufügen

es ein bisschen später ist und Antwort ist nicht perfekt, aber es macht den Job für mich (in ES6):

private createNewPdf() { 
    this.positionY = MARGIN_TOP; // margin top 
    this.pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', lineHeight: 1 }); 
} 

// convert mm to fontSize 
private setTextHeight(this.textHeight) { 
    let fontSize = this.textHeight * 4; 
    this.pdf.setFontSize(fontSize); 
} 

private addText(text) { 
    this.setTextHeight(textHeight); 
    if (this.positionY + textHeight > (this.pdf.internal.pages.height - MARGIN_BOTTOM)) { 
     this.addPage(); 
    } 
    this.pdf.text(MARGIN_LEFT, this.positionY + this.textHeight, text); 
    this.positionY += textHeight; 
} 

private addPage() { 
    this.pdf.addPage(); 
    this.positionY = MARGIN_TOP; 
} 

So, nachdem Sie müssen nur:

this.textHeight = 3; // mm 
this.positionY = 0; // position of previous text 
this.pdf = null; 

this.createNewPdf(); 
this.addText('My first text'); 
this.addText('My second text'); 
... 

Und wenn es mehr Text als Ort ist, wird Seite automatisch mit MARGIN_TOP hinzugefügt werden (Sie müssen t definieren sein)

Verwandte Themen