2013-08-29 81 views
3

在jsPDF的documentation我無法找到一種方法或函數來增加文本行之間的空間。我想知道是否有人知識豐富會點頭分享一些他/她的知識:)。非常感謝。jsPDF調整文本行間距

+1

待辦事項你是指在'text'函數中使用字符串數組時? – Joqus

回答

3

API.text的輸出確定線高度使用lineHeightProportion:

 out(
      'BT\n/' + 
       activeFontKey + ' ' + activeFontSize + ' Tf\n' + // font face, style, size 
       (activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing 
       textColor + 
       '\n' + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' Td\n(' + 
       str + 
       ') Tj\nET' 
     ); 

改變上述各行到

   // (activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing 
       (activeFontSize * this.lineHeightProportion) + ' TL\n' + // line spacing 

並設置變量:

pdf = new jsPDF("portrait", "in", "letter"); 
pdf.lineHeightProportion = 2; 

應該做訣竅。

https://github.com/MrRio/jsPDF/pull/167

4

,您還可以在jsPDF構造函數添加參數:

file = new jsPDF({orientation: "p", lineHeight: 1.5)}) 

從jsPDF碼(功能jsPDF(方向,單位,格式,compressPdf)):

var options = {}; 

if (typeof orientation === 'object') { 
    options = orientation; 

    orientation = options.orientation; 
    unit = options.unit || unit; 
    format = options.format || format; 
    compressPdf = options.compress || options.compressPdf || compressPdf; 
} 

// Default options 
unit = unit || 'mm'; 
format = format || 'a4'; 
orientation = ('' + (orientation || 'P')).toLowerCase(); 

var format_as_string = ('' + format).toLowerCase(), 
    compress = !!compressPdf && typeof Uint8Array === 'function', 
    textColor = options.textColor || '0 g', 
    drawColor = options.drawColor || '0 G', 
    activeFontSize = options.fontSize || 16, 
    lineHeightProportion = options.lineHeight || 1.15, 
    lineWidth = options.lineWidth || 0.200025; // 2mm