代码之家  ›  专栏  ›  技术社区  ›  Niklesh Raut

如何在“pdfmake”javascript库中设置水印字体大小

  •  0
  • Niklesh Raut  · 技术社区  · 6 年前

    我在用 pdfmake 在angular js中生成pdf。

    我正在尝试缩小/设置相同的字体大小,水印应该以pdf格式显示,根据动态文本。

    我试过在配置下输入, playground

    var dd = {
        content: [
            'First paragraph',
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ],
        watermark:{
            text:"Niklesh Raut",
             header: {
           fontSize: 22,
           bold: true
         },
         anotherStyle: {
           italic: true,
           alignment: 'right'
         }
    
        }
    
    }
    

    也试过了。

    var dd = {
        content: [
            'First paragraph',
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ],
        watermark:{
            text:"Niklesh Raut",
            styles: {
               fontSize: 22,
               bold: true
            }
    
        }
    
    }
    

    但没有运气。

    问题 :如何设置/减小水印的字体大小?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Niklesh Raut    6 年前

    pdfmake 水印适合页面,即使字符长度为1,因此添加空格使单词具有固定长度,下面有代码

    var stars = '                                   ';
        var name = "Niklesh Raut";
        var center = parseInt(stars.length/2) - parseInt(name.length/2);
        var starsArr = stars.split("");
        var nameArr = name.split("");
        for(let i=0;i<name.length;i++){
        	starsArr[center+i] = nameArr[i];
        }
        console.log('|'+starsArr.join("")+'|');

    用这个做水印

    var dd = {
        content: [
            'First paragraph',
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ],
        watermark:{
            text:'              Niklesh Raut              ',
        }
    
    }
    
        2
  •  0
  •   BharathwajRK    6 年前

    在以下样本中找到Hi https://itnext.io/angularjs-exporting-to-pdf-using-pdfmake-js-library-49f3afec97ef

        var docDefinition = {
                  header: function() {
                        return [
                            {
                                style: 'table',
                                margin: [62,35,62,35],
                                table: {
                                    widths: ['*', '*'],
                                    headerRows: 0,
                                    body: [
                                        [
                                            {text: 'Booking Summary', style: 'topHeader', alignment: 'left'},
                                            {
                                                'base64-image-string-goes-here',
                                                width: 150,
                                                alignment: 'right'
                                            }
                                        ]
                                    ]
                                },
                                layout: 'noBorders'
                            }
                        ]
                    },
                    footer: function(currentPage, pageCount) { 
                        return [
                            {text: currentPage.toString() + ' of ' + pageCount, alignment: 'center', style: 'footer'}
                        ]
                    },
                    content: [],
                    pageSize: 'A4',
                    pageMargins: [62,80,62,80],
                    styles: {
                        topHeader: {
                            fontSize: 20,
                            bold: true,
                            margin: [0, 6, 0, 30],
                            alignment: 'left'
                        },
                        table: {
                            fontSize: 8,
                            alignment: 'left',
                            color: 'black',
                            margin: [0, 5, 0, 15]
                        },
                        header: {       
                            fontSize: 16,
                            bold: true,
                            margin: [0, 10, 0, 15],
                            alignment: 'left'
                        },
                        footer: {
                            fontSize: 8,
                            margin: [0, 25, 0, 17],
                            alignment: 'center'
                        }
                    }
                };
              pdfMake.createPdf(docDefinition).download();
        };